Skip to content

Commit 2e24044

Browse files
author
Fredrik Lundh
committed
from the really-stupid-bug department: uppercase literals should match
uppercase strings also when the IGNORECASE flag is set (bug python#128899) (also added test cases for recently fixed bugs to the regression suite -- or in other words, check in re_tests.py too...)
1 parent 48450cf commit 2e24044

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

Lib/sre_compile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ def _compile(code, pattern, flags):
2323
if op in (LITERAL, NOT_LITERAL):
2424
if flags & SRE_FLAG_IGNORECASE:
2525
emit(OPCODES[OP_IGNORE[op]])
26+
emit(_sre.getlower(av, flags))
2627
else:
2728
emit(OPCODES[op])
28-
emit(av)
29+
emit(av)
2930
elif op is IN:
3031
if flags & SRE_FLAG_IGNORECASE:
3132
emit(OPCODES[OP_IGNORE[op]])

Lib/test/re_tests.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@
598598

599599
(r'\xff', '\377', SUCCEED, 'found', chr(255)),
600600
# new \x semantics
601-
(r'\x00ff', '\377', FAIL, 'found', chr(255)),
601+
(r'\x00ff', '\377', FAIL),
602602
# (r'\x00ff', '\377', SUCCEED, 'found', chr(255)),
603603
(r'\t\n\v\r\f\a\g', '\t\n\v\r\f\ag', SUCCEED, 'found', '\t\n\v\r\f\ag'),
604604
('\t\n\v\r\f\a\g', '\t\n\v\r\f\ag', SUCCEED, 'found', '\t\n\v\r\f\ag'),
@@ -610,11 +610,13 @@
610610

611611
# xmllib problem
612612
(r'(([a-z]+):)?([a-z]+)$', 'smil', SUCCEED, 'g1+"-"+g2+"-"+g3', 'None-None-smil'),
613-
# bug 111869 (PRE/PCRE fails on this one, SRE doesn't)
613+
# bug 110866: reference to undefined group
614+
(r'((.)\1+)', '', SYNTAX_ERROR),
615+
# bug 111869: search (PRE/PCRE fails on this one, SRE doesn't)
614616
(r'.*d', 'abc\nabd', SUCCEED, 'found', 'abd'),
615617
# bug 112468: various expected syntax errors
616-
('(', '', SYNTAX_ERROR),
617-
('[\\41]', '!', SUCCEED, 'found', '!'),
618+
(r'(', '', SYNTAX_ERROR),
619+
(r'[\41]', '!', SUCCEED, 'found', '!'),
618620
# bug 114033: nothing to repeat
619621
(r'(x?)?', 'x', SUCCEED, 'found', 'x'),
620622
# bug 115040: rescan if flags are modified inside pattern
@@ -623,5 +625,15 @@
623625
(r'(?<!abc)(d.f)', 'abcdefdof', SUCCEED, 'found', 'dof'),
624626
# bug 116251: character class bug
625627
(r'[\w-]+', 'laser_beam', SUCCEED, 'found', 'laser_beam'),
626-
628+
# bug 123769+127259: non-greedy backtracking bug
629+
(r'.*?\S *:', 'xx:', SUCCEED, 'found', 'xx:'),
630+
(r'a[ ]*?\ (\d+).*', 'a 10', SUCCEED, 'found', 'a 10'),
631+
(r'a[ ]*?\ (\d+).*', 'a 10', SUCCEED, 'found', 'a 10'),
632+
# bug 127259: \Z shouldn't depend on multiline mode
633+
(r'(?ms).*?x\s*\Z(.*)','xx\nx\n', SUCCEED, 'g1', ''),
634+
# bug 128899: uppercase literals under the ignorecase flag
635+
(r'(?i)M+', 'MMM', SUCCEED, 'found', 'MMM'),
636+
(r'(?i)m+', 'MMM', SUCCEED, 'found', 'MMM'),
637+
(r'(?i)[M]+', 'MMM', SUCCEED, 'found', 'MMM'),
638+
(r'(?i)[m]+', 'MMM', SUCCEED, 'found', 'MMM'),
627639
]

0 commit comments

Comments
 (0)