FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-156185: Ignore all ASCII whitespace in re \p{} property names by Georgefifth · Pull Request #156304 · python/cpython · GitHub

/ cpython Public
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
8 changes: 4 additions & 4 deletions Lib/re/_properties.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ def _analytic_ranges():


def _normalize(name):
# Unicode property and value names are matched loosely: case, spaces,
# hyphens and underscores are not significant, and an initial "is" prefix
# is ignored (UAX #44 5.9, "Matching Rules", UAX44-LM3;
# Unicode property and value names are matched loosely: case, whitespace
# and hyphens and underscores are not significant, and an initial "is"
# prefix is ignored (UAX #44 5.9, "Matching Rules", UAX44-LM3;
# https://www.unicode.org/reports/tr44/).
name = name.lower().replace("_", "").replace("-", "").replace(" ", "")
name = "".join(ch for ch in name.lower() if ch not in " \t\n\r\f\v_-")
# Strip a leading "is", unless "is" is the whole name and so not a prefix
# (e.g. the Line_Break value lb=IS).
if name != "is":
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_re.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,12 @@ def test_property_escapes(self):
self.assertTrue(re.fullmatch(r'\p{General_Category=Lu}+', 'ABC'))
self.assertTrue(re.fullmatch(r'\p{ lu }+', 'ABC'))
self.assertTrue(re.fullmatch(r'\p{LU}+', 'ABC'))
# All ASCII whitespace is ignored, not just spaces (UAX44-LM3;
# gh-156185).
for ws in " \t\n\r\f\v":
with self.subTest(ws=ws):
self.assertTrue(re.fullmatch(r'\p{L%su}+' % ws, 'ABC'))
self.assertTrue(re.fullmatch(r'\p{gc%s=L%su}+' % (ws, ws), 'ABC'))
# An initial "is" prefix is ignored (UAX44-LM3), on the property name
# and on a gc value; "is" alone is not a prefix (cf. lb=IS).
self.assertTrue(re.fullmatch(r'\p{isLu}+', 'ABC'))
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
``\p{property}`` and ``\p{property=value}`` regex escapes now ignore all
ASCII whitespace in property and value names, as documented, instead of
only spaces.
Loading

Back | FazBrowse Home | New Git URL