8000 [3.13] gh-136028: Fix parsing month names containing "İ" (U+0130) in … · python/cpython@e7a8f96 · GitHub
[go: up one dir, main page]

Skip to content

Commit e7a8f96

Browse files
[3.13] gh-136028: Fix parsing month names containing "İ" (U+0130) in strptime() (GH-136029) (GH-136038)
This affects locales az_AZ, ber_DZ, ber_MA and crh_UA. (cherry picked from commit 731f5b8) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent 1e972c7 commit e7a8f96

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

Lib/_strptime.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ def _findall(haystack, needle):
4242
yield i
4343
i += len(needle)
4444

45+
def _fixmonths(months):
46+
yield from months
47+
# The lower case of 'İ' ('\u0130') is 'i\u0307'.
48+
# The re module only supports 1-to-1 character matching in
49+
# case-insensitive mode.
50+
for s in months:
51+
if 'i\u0307' in s:
52+
yield s.replace('i\u0307', '\u0130')
4553

4654
lzh_TW_alt_digits = (
4755
# 〇:一:二:三:四:五:六:七:八:九
@@ -366,8 +374,8 @@ def __init__(self, locale_time=None):
366374
'z': r"(?P<z>[+-]\d\d:?[0-5]\d(:?[0-5]\d(\.\d{1,6})?)?|(?-i:Z))",
367375
'A': self.__seqToRE(self.locale_time.f_weekday, 'A'),
368376
'a': self.__seqToRE(self.locale_time.a_weekday, 'a'),
369-
'B': self.__seqToRE(self.locale_time.f_month[1:], 'B'),
370-
'b': self.__seqToRE(self.locale_time.a_month[1:], 'b'),
377+
'B': self.__seqToRE(_fixmonths(self.locale_time.f_month[1:]), 'B'),
378+
'b': self.__seqToRE(_fixmonths(self.locale_time.a_month[1:]), 'b'),
371379
'p': self.__seqToRE(self.locale_time.am_pm, 'p'),
372380
'Z': self.__seqToRE((tz for tz_names in self.locale_time.timezone
373381
for tz in tz_names),

Lib/test/test_strptime.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,15 @@ def test_month_locale(self):
340340
self.roundtrip('%B', 1, (1900, m, 1, 0, 0, 0, 0, 1, 0))
341341
self.roundtrip('%b', 1, (1900, m, 1, 0, 0, 0, 0, 1, 0))
342342

343+
@run_with_locales('LC_TIME', 'az_AZ', 'ber_DZ', 'ber_MA', 'crh_UA')
344+
def test_month_locale2(self):
345+
# Test for month directives
346+
# Month name contains 'İ' ('\u0130')
347+
self.roundtrip('%B', 1, (2025, 6, 1, 0, 0, 0, 6, 152, 0))
348+
self.roundtrip('%b', 1, (2025, 6, 1, 0, 0, 0, 6, 152, 0))
349+
self.roundtrip('%B', 1, (2025, 7, 1, 0, 0, 0, 1, 182, 0))
350+
self.roundtrip('%b', 1, (2025, 7, 1, 0, 0, 0, 1, 182, 0))
351+
343352
def test_day(self):
344353
# Test for day directives
345354
self.roundtrip('%d %Y', 2)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix parsing month names containing "İ" (U+0130, LATIN CAPITAL LETTER I WITH
2+
DOT ABOVE) in :func:`time.strptime`. This affects locales az_AZ, ber_DZ,
3+
ber_MA and crh_UA.

0 commit comments

Comments
 (0)
0