Skip to content

Escape locale strings in the from_format pattern - #1030

Open
Sharadhi-v98 wants to merge 1 commit into
python-pendulum:masterfrom
Sharadhi-v98:from-format-escape-locale-names
Open

Sharadhi-v98 wants to merge 1 commit into
python-pendulum:masterfrom
Sharadhi-v98:from-format-escape-locale-names

Conversation

@Sharadhi-v98

Copy link
Copy Markdown
  1. from_format joins the locale's month names, day names, day periods and ordinal suffixes into its pattern unescaped, so the dot in abbreviations like "févr." or "Dez." matches any character.
  2. The name lookup then returns None, but the guard after it tests value instead of the lookup result, so the month or weekday is dropped and the default is used. pendulum.from_format("15 févrX 2024", "D MMM YYYY", locale="fr") returns 2024-01-15 and "1 juil, 2024" returns 2024-01-01.

Escaped the locale strings and made the guard check the lookup result, so these now raise ValueError.

  • Added tests for changed code.
  • Updated documentation for changed code.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant