summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorGustavo Niemeyer <gustavo@niemeyer.net>2003-04-27 12:34:14 (GMT)
committerGustavo Niemeyer <gustavo@niemeyer.net>2003-04-27 12:34:14 (GMT)
commitc34f2555bd414254f941d0659ba9c229b96ec728 (patch)
tree7c7a681087d14a07eecae1aa2d870e3dd44af452 /Lib/test
parent9dcbbea87867f38f7994dd96388266114ef0c162 (diff)
downloadcpython-c34f2555bd414254f941d0659ba9c229b96ec728.zip
cpython-c34f2555bd414254f941d0659ba9c229b96ec728.tar.gz
cpython-c34f2555bd414254f941d0659ba9c229b96ec728.tar.bz2
Applied patch #725106, by Greg Chapman, fixing capturing groups
within repeats of alternatives. The only change to the original patch was to convert the tests to the new test_re.py file. This patch fixes cases like: >>> re.match('((a)|b)*', 'abc').groups() ('b', '') Which is wrong (it's impossible to match the empty string), and incompatible with other regex systems, like the following examples show: % perl -e '"abc" =~ /^((a)|b)*/; print "$1 $2\n";' b a % echo "abc" | sed -r -e "s/^((a)|b)*/\1 \2|/" b a|c
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_re.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index 2430790..7ba9a1b 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -276,6 +276,25 @@ class ReTests(unittest.TestCase):
self.assertEqual(re.match(r'((.%s):)?z'%op, 'a:z').groups(),
('a:', 'a'))
+ def test_bug_725106(self):
+ # capturing groups in alternatives in repeats
+ self.assertEqual(re.match('^((a)|b)*', 'abc').groups(),
+ ('b', 'a'))
+ self.assertEqual(re.match('^(([ab])|c)*', 'abc').groups(),
+ ('c', 'b'))
+ self.assertEqual(re.match('^((d)|[ab])*', 'abc').groups(),
+ ('b', None))
+ self.assertEqual(re.match('^((a)c|[ab])*', 'abc').groups(),
+ ('b', None))
+ self.assertEqual(re.match('^((a)|b)*?c', 'abc').groups(),
+ ('b', 'a'))
+ self.assertEqual(re.match('^(([ab])|c)*?d', 'abcd').groups(),
+ ('c', 'b'))
+ self.assertEqual(re.match('^((d)|[ab])*?c', 'abc').groups(),
+ ('b', None))
+ self.assertEqual(re.match('^((a)c|[ab])*?c', 'abc').groups(),
+ ('b', None))
+
def test_finditer(self):
iter = re.finditer(r":+", "a:b::c:::d")
self.assertEqual([item.group(0) for item in iter],