[3.14] gh-155292: Don't consider Unicode codepoint attributes outside RFC 3454 (GH-155293) by encukou · Pull Request #156020 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
316 changes: 250 additions & 66 deletions Lib/stringprep.py

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions Lib/test/test_codecs.py
9 changes: 9 additions & 0 deletions Lib/test/test_unicodedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,15 @@ def test_bidirectional(self):
self.assertRaises(TypeError, self.db.bidirectional)
self.assertRaises(TypeError, self.db.bidirectional, 'xx')

def test_bidirectional_unassigned(self):
self.assertEqual(self.db.bidirectional('\u0378'), '')
self.assertEqual(self.db.bidirectional('\u077F'), '' if self.old else 'AL')
self.assertEqual(self.db.bidirectional('\u20CF'), '')
self.assertEqual(self.db.bidirectional('\u0590'), '')
self.assertEqual(self.db.bidirectional('\uFFFF'), '')
self.assertEqual(self.db.bidirectional('\U0001FFFE'), '')
self.assertEqual(self.db.bidirectional('\U00010D01'), '' if self.old else 'AL')

def test_decomposition(self):
self.assertEqual(self.db.decomposition('\uFFFE'),'')
self.assertEqual(self.db.decomposition('\u00bc'), '<fraction> 0031 2044 0034')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Change the :mod:`stringprep` module and :mod:`encodings.idna` codec to not
consider Unicode codepoint attributes beyond those defined in :rfc:`3454`.
15 changes: 15 additions & 0 deletions Tools/unicode/makeunicodedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import dataclasses
import os
import subprocess
import sys
import zipfile

Expand Down Expand Up @@ -126,6 +127,7 @@ def maketables(trace=0):
makeunicodename(unicode, trace)
makeunicodedata(unicode, trace)
makeunicodetype(unicode, trace)
makestringprep()


# --------------------------------------------------------------------
Expand Down Expand Up @@ -711,6 +713,19 @@ def makeunicodename(unicode, trace):
fprint(' "%s",' % prefix)
fprint('};')


def makestringprep():
FILE = "Lib/stringprep.py"

print("--- Preparing", FILE, "...")

MKSTRINGPREP = "Tools/unicode/mkstringprep.py"

with open(FILE, "w") as f:
f.truncate()
subprocess.check_call([sys.executable, MKSTRINGPREP], stdout=f)


def merge_old_version(version, new, old):
# Changes to exclusion file not implemented yet
if old.exclusions != new.exclusions:
Expand Down
93 changes: 63 additions & 30 deletions Tools/unicode/mkstringprep.py
Loading