Skip to content

Commit 7e109d0

Browse files
sethmlarsonStanFromIrelandencukou
authored
gh-155292: Don't consider Unicode codepoint attributes outside RFC 3454 (GH-155293)
Due to a bug, some Unicode codepoint attributes were considered for characters not yet defined in Unicode 3.2.0 or attributes which changed in later Unicode versions. RFC 3454 (StringPrep) requires using Unicode 3.2.0 strictly. Co-authored-by: Stan Ulbrych <89152624+stanfromireland@users.noreply.github.com> Co-authored-by: Petr Viktorin <encukou@gmail.com>
1 parent f2eaf17 commit 7e109d0

7 files changed

Lines changed: 1924 additions & 1351 deletions

File tree

Lib/stringprep.py

Lines changed: 257 additions & 66 deletions
Large diffs are not rendered by default.

Lib/test/test_codecs.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,6 +1695,15 @@ def test_builtin_encode(self):
16951695
self.assertEqual("pyth\xf6n.org".encode("idna"), b"xn--pythn-mua.org")
16961696
self.assertEqual("pyth\xf6n.org.".encode("idna"), b"xn--pythn-mua.org.")
16971697

1698+
@support.subTests(['unicode', 'encoded'], [
1699+
('\N{CHEROKEE LETTER A}\N{CHEROKEE LETTER A}', b"xn--58da"),
1700+
('\N{GEORGIAN CAPITAL LETTER AN}.', b"xn--7md."),
1701+
('\N{CYRILLIC LETTER PALOCHKA}.example', b"xn--d5a.example"),
1702+
('\N{ROMAN NUMERAL REVERSED ONE HUNDRED}.example.', b"xn--q5g.example."),
1703+
])
1704+
def test_new_unicode_case_folding(self, unicode, encoded):
1705+
self.assertEqual(unicode.encode("idna"), encoded)
1706+
16981707
def test_builtin_encode_invalid(self):
16991708
for case, expected in self.invalid_encode_testcases:
17001709
with self.subTest(case=case, expected=expected):

Lib/test/test_unicodedata.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def test_category(self):
321321
self.assertRaises(TypeError, self.db.category, 'xx')
322322

323323
def test_bidirectional(self):
324-
self.assertEqual(self.db.bidirectional('\uFFFE'), 'BN')
324+
self.assertEqual(self.db.bidirectional('\uFFFE'), '' if self.old else 'BN')
325325
self.assertEqual(self.db.bidirectional(' '), 'WS')
326326
self.assertEqual(self.db.bidirectional('A'), 'L')
327327
self.assertEqual(self.db.bidirectional('\U00020000'), 'L')
@@ -350,15 +350,13 @@ def test_bidirectional(self):
350350
self.assertRaises(TypeError, self.db.bidirectional, 'xx')
351351

352352
def test_bidirectional_unassigned(self):
353-
if self.old:
354-
return
355-
self.assertEqual(self.db.bidirectional('\u0378'), 'L')
356-
self.assertEqual(self.db.bidirectional('\u077F'), 'AL')
357-
self.assertEqual(self.db.bidirectional('\u20CF'), 'ET')
358-
self.assertEqual(self.db.bidirectional('\u0590'), 'R')
359-
self.assertEqual(self.db.bidirectional('\uFFFF'), 'BN')
360-
self.assertEqual(self.db.bidirectional('\U0001FFFE'), 'BN')
361-
self.assertEqual(self.db.bidirectional('\U00010D01'), 'AL')
353+
self.assertEqual(self.db.bidirectional('\u0378'), '' if self.old else 'L')
354+
self.assertEqual(self.db.bidirectional('\u077F'), '' if self.old else 'AL')
355+
self.assertEqual(self.db.bidirectional('\u20CF'), '' if self.old else 'ET')
356+
self.assertEqual(self.db.bidirectional('\u0590'), '' if self.old else 'R')
357+
self.assertEqual(self.db.bidirectional('\uFFFF'), '' if self.old else 'BN')
358+
self.assertEqual(self.db.bidirectional('\U0001FFFE'), '' if self.old else 'BN')
359+
self.assertEqual(self.db.bidirectional('\U00010D01'), '' if self.old else 'AL')
362360

363361
def test_decomposition(self):
364362
self.assertEqual(self.db.decomposition('\uFFFE'),'')
@@ -1104,9 +1102,9 @@ def test_block_invalid_input(self):
11041102
class Unicode_3_2_0_FunctionsTest(unittest.TestCase, BaseUnicodeFunctionsTest):
11051103
db = unicodedata.ucd_3_2_0
11061104
old = True
1107-
expectedchecksum = ('cb5bbbd1f55b67371e18222b90a8e21c87f16b72'
1105+
expectedchecksum = ('883824cb6c0ccf994e4451ebf281e2d6d479af47'
11081106
if quicktest else
1109-
'74936dffe949d99203a47e6a66565b2fc337bae7')
1107+
'68cd01e2c680b851c1fcab012efb5635b2229c2b')
11101108

11111109

11121110
class UnicodeMiscTest(unittest.TestCase):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Change the :mod:`stringprep` module and :mod:`encodings.idna` codec to not
2+
consider Unicode codepoint attributes beyond those defined in :rfc:`3454`.

0 commit comments

Comments
 (0)