python / python/cpython

`\p{...}` names ignore only spaces, though the docs promise whitespace

Offen
#156,185 1 Kommentar 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@serhiy-storchaka arbeitet bereits daran.

Seit 21.8.2026.

3.16 stdlib topic-regex type-bug
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Bug description:

Doc/library/re.rst says of the \p{property=value} escape: "Property and value names are matched loosely: case, whitespace, '-' and '_' are ignored." _normalize() in Lib/re/_properties.py removes only U+0020, so a property or value name spelled with a tab, newline, carriage return, vertical tab or form feed is rejected.

import re

for name in ['L u', 'L\tu']:
    try:
        re.compile(r'\p{%s}' % name)
        print(repr(name), 'accepted')
    except re.PatternError as e:
        print(repr(name), 'rejected:', e.msg)
'L u' accepted
'L\tu' rejected: unknown property name 'L\tu'

Expected: both accepted, since the documentation says whitespace is ignored. UAX #44 UAX44-LM3, cited by _normalize()'s own comment, says to ignore whitespace rather than spaces.

Either side can change: narrow the documentation to "spaces", or strip \t\n\v\f\r in _normalize() to match UAX44-LM3. \p{...} is new in 3.16 and has not shipped, and the only user-visible effect either way is which spellings raise PatternError at compile time.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs
  • gh-156304

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.