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

Skip to content

Commit 731f5b8

Browse files
gh-136028: Fix parsing month names containing "İ" (U+0130) in strptime() (GH-136029)
This affects locales az_AZ, ber_DZ, ber_MA and crh_UA.
1 parent de0d014 commit 731f5b8

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
@@ -337,6 +337,15 @@ def test_month_locale(self):
337337
self.roundtrip('%B', 1, (1900, m, 1, 0, 0, 0, 0, 1, 0))
338338
self.roundtrip('%b', 1, (1900, m, 1, 0, 0, 0, 0, 1, 0))
339339

340+
@run_with_locales('LC_TIME', 'az_AZ', 'ber_DZ', 'ber_MA', 'crh_UA')
341+
def test_month_locale2(self):
342+
# Test for month directives
343+
# Month name contains 'İ' ('\u0130')
344+
self.roundtrip('%B', 1, (2025, 6, 1, 0, 0, 0, 6, 152, 0))
345+
self.roundtrip('%b', 1, (2025, 6, 1, 0, 0, 0, 6, 152, 0))
346+
self.roundtrip('%B', 1, (2025, 7, 1, 0, 0, 0, 1, 182, 0))
347+
self.roundtrip('%b', 1, (2025, 7, 1, 0, 0, 0, 1, 182, 0))
348+
340349
def test_day(self):
341350
# Test for day directives
342351
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