regex: Improper handling of Unicode Properties in character set 3.16a2
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 56/100
Piste de recherche
Start in Lib/re/_compiler.py at _optimize_charset() and inspect how IN_UNI_IGNORE handles category items when a set contains cased literals or ranges. Use the examples in the issue as regression cases, then run the relevant regular expression tests. Done means the category properties and their negations preserve the reported IGNORECASE behavior while existing set matching continues to work.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Bug report
I found this when evaluating the Unicode Properties in the recent alpha release for Re. I realize this work is a WIP, but figured I'd share in case this issue wasn't already known.
With re.IGNORECASE, a character set that contains a case-sensitive property escape (\p{Lu}, \p{Lt}, \p{Uppercase}, \p{Lowercase}, or their \P{...} forms) together with a cased literal or range gives the wrong results. Adding a member to a set can remove matches:
>>> import re
>>> re.fullmatch(r'[\p{Lu}]', 'A', re.IGNORECASE)
<re.Match object; span=(0, 1), match='A'>
>>> re.fullmatch(r'[\p{Lu}x]', 'A', re.IGNORECASE) # expected a match
>>> re.fullmatch(r'[\p{Lu}x]', 'A')
<re.Match object; span=(0, 1), match='A'>
Below is info gathered by AI, hopefully it is helpful, but the important part is the behavior that doesn't match expectations.
More examples, all with re.IGNORECASE:
| Pattern | String | Result | Expected |
|---|---|---|---|
[\p{Lu}x] |
'A' |
no match | match |
[\p{Lu}a-c] |
'Z' |
no match | match |
[^\p{Lu}x] |
'A' |
match | no match |
[\P{Lu}x] |
'A' |
match | no match |
[\p{Lt}x] |
'Dž' |
no match | match |
[\p{Uppercase}x] |
'A' |
no match | match |
[\p{Lowercase}x] |
'A' |
match | no match |
"Expected" is how these properties already behave with IGNORECASE outside a set, or as the only member of a
set: \p{Lu} and [\p{Lu}] match 'A' but not 'a'.
The same happens with an inline (?i:...), and with re.ASCII | re.IGNORECASE for ASCII characters. Sets without
a cased literal or range, such as [\p{Lu}1] and [\p{Lu}\d], are not affected.
Cause: in Lib/re/_compiler.py, when a set under IGNORECASE contains a cased literal or range (hascased
from _optimize_charset()), the whole set is compiled as IN_UNI_IGNORE (IN_IGNORE with ASCII). Those
opcodes lowercase the character before testing it against every item in the set, including CATEGORY items. The
literals in the set are already lowercased, so they still match correctly, but the categories are now tested
against the lowercased character: 'A' becomes 'a' before the Lu test.
For the categories that existed before 3.16 (\d, \s, \w), lowercasing a character never changes whether it is
in the category, so this was harmless. It does for the new CATEGORY_LU, CATEGORY_TITLE, CATEGORY_UPPER and
CATEGORY_LOWER, and their negations. Checking every code point that changes when lowercased, these are the only
supported properties whose membership changes (Lu, Lt, Uppercase, Lowercase).
A fix could test CATEGORY items against the original character rather than the lowercased one in the
ignore-case set opcodes, or have the compiler keep those categories out of the ignore-case check.
CPython versions tested on:
3.16
Operating systems tested on:
macOS
- Langage dominant
- Python
- Étoiles
- 78.2k
- Forks
- 36.6k
- Merge moyen
- 19 h 57 min
- PR mergées (30 j)
- 630
Préparer son environnement
Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de python/cpython
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
stdlib type-bug
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
Les mainteneurs répondent en général sous 1 jour
-
extension-modules stdlib topic-XML type-bug
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
python/cpython#161807 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
stdlib type-feature
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
python/cpython#161788 · 7 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
extension-modules topic-IO type-bug
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de python/cpython
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
cpp-best-practices/project_validator#267 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Project-N-E-K-O/N.E.K.O#3725 ·
Les mainteneurs répondent en général sous 1 jour
-
[Bug] Sending a Telegram message chain twice duplicates mentionsPeut-être pris @123XieC l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
AstrBotDevs/AstrBot#11125 ·
Les mainteneurs répondent en général sous 1 jour
-
backend bug priority: high
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
nooriegarg/ContribIQ#73 ·
Les mainteneurs répondent en général sous 1 jour
-
bug p3 security
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
amd/gaia#8197 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour