[pypy-svn] r61054 - in pypy/trunk/pypy/module/_sre: . test

fijal at codespeak.net fijal at codespeak.net
Sat Jan 17 13:03:19 CET 2009


Author: fijal
Date: Sat Jan 17 13:03:17 2009
New Revision: 61054

Modified:
   pypy/trunk/pypy/module/_sre/app_sre.py
   pypy/trunk/pypy/module/_sre/test/test_app_sre.py
Log:
I think *this* is the real fix for the problem. And a test.


Modified: pypy/trunk/pypy/module/_sre/app_sre.py
==============================================================================
--- pypy/trunk/pypy/module/_sre/app_sre.py	(original)
+++ pypy/trunk/pypy/module/_sre/app_sre.py	Sat Jan 17 13:03:17 2009
@@ -81,7 +81,7 @@
         sublist = []
 
         need_unicode = (isinstance(string, unicode) or
-                        isinstance(self.pattern, unicode))
+                        isinstance(repl, unicode))
         n = last_pos = 0
         while not count or n < count:
             state.reset()
@@ -109,7 +109,7 @@
         if last_pos < state.end:
             sublist.append(string[last_pos:state.end])
 
-        if n == 0 or len(sublist) == 1:
+        if n == 0:
             # not just an optimization -- see test_sub_unicode
             return string, n
 

Modified: pypy/trunk/pypy/module/_sre/test/test_app_sre.py
==============================================================================
--- pypy/trunk/pypy/module/_sre/test/test_app_sre.py	(original)
+++ pypy/trunk/pypy/module/_sre/test/test_app_sre.py	Sat Jan 17 13:03:17 2009
@@ -913,6 +913,9 @@
         s.assert_match(opcodes, ["a"])
         s.assert_no_match(opcodes, ["ab"])
 
+    def test_bug(self):
+        import re
+        assert re.sub('=\w{2}', 'x', '=CA') == 'x'
 
 class AppTestOptimizations:
     """These tests try to trigger optmized edge cases."""



More information about the Pypy-commit mailing list