Skip to content

Commit c24388e

Browse files
taleinatAlexey Izbyshevpganssle
committed
Add tests for surrogate code points
Co-authored-by: Alexey Izbyshev <[email protected]> Co-authored-by: Paul Ganssle <[email protected]>
1 parent dd82aa0 commit c24388e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Lib/test/datetimetester.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,7 @@ def test_fromisoformat_fails(self):
16671667
# Test that fromisoformat() fails on invalid values
16681668
bad_strs = [
16691669
'', # Empty string
1670+
'\ud800', # bpo-34454: Surrogate code point
16701671
'009-03-04', # Not 10 characters
16711672
'123456789', # Not a date
16721673
'200a-12-04', # Invalid character in year
@@ -1675,6 +1676,7 @@ def test_fromisoformat_fails(self):
16751676
'2009-01-32', # Invalid day
16761677
'2009-02-29', # Invalid leap day
16771678
'20090228', # Valid ISO8601 output not from isoformat()
1679+
'2009\ud80002\ud80028', # Separators are surrogate codepoints
16781680
]
16791681

16801682
for bad_str in bad_strs:
@@ -2587,7 +2589,8 @@ def test_fromisoformat_separators(self):
25872589
' ', 'T', '\u007f', # 1-bit widths
25882590
'\u0080', 'ʁ', # 2-bit widths
25892591
'ᛇ', '時', # 3-bit widths
2590-
'🐍' # 4-bit widths
2592+
'🐍', # 4-bit widths
2593+
'\ud800', # bpo-34454: Surrogate code point
25912594
]
25922595

25932596
for sep in separators:
@@ -2639,6 +2642,7 @@ def test_fromisoformat_fails_datetime(self):
26392642
# Test that fromisoformat() fails on invalid values
26402643
bad_strs = [
26412644
'', # Empty string
2645+
'\ud800', # bpo-34454: Surrogate code point
26422646
'2009.04-19T03', # Wrong first separator
26432647
'2009-04.19T03', # Wrong second separator
26442648
'2009-04-19T0a', # Invalid hours
@@ -2652,6 +2656,8 @@ def test_fromisoformat_fails_datetime(self):
26522656
'2009-04-19T03:15:45.123456+24:30', # Invalid time zone offset
26532657
'2009-04-19T03:15:45.123456-24:30', # Invalid negative offset
26542658
'2009-04-10ᛇᛇᛇᛇᛇ12:15', # Too many unicode separators
2659+
'2009-04\ud80010T12:15', # Surrogate char in date
2660+
'2009-04-10T12\ud80015', # Surrogate char in time
26552661
'2009-04-19T1', # Incomplete hours
26562662
'2009-04-19T12:3', # Incomplete minutes
26572663
'2009-04-19T12:30:4', # Incomplete seconds
@@ -3521,6 +3527,7 @@ def test_fromisoformat_timespecs(self):
35213527
def test_fromisoformat_fails(self):
35223528
bad_strs = [
35233529
'', # Empty string
3530+
'12\ud80000', # Invalid separator - surrogate char
35243531
'12:', # Ends on a separator
35253532
'12:30:', # Ends on a separator
35263533
'12:30:15.', # Ends on a separator

0 commit comments

Comments
 (0)