Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/utils/str.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ def perlReToReplacer(s):
regexp = regexp.replace('\x08', r'\b')
replace = replace.replace('\\'+sep, sep)
for i in range(10):
replace = replace.replace(chr(i), r'\%s' % i)
replace = replace.replace(chr(i), r'\g<%s>' % i)
replace = replace.replace(r'\0', r'\g<0>')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line looks redundant

g = False
if 'g' in flags:
g = True
Expand Down
4 changes: 4 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ def testPerlReToReplacer(self):
self.assertEqual(f('foo'), 'foo/bar')
f = PRTR('s/^/foo/')
self.assertEqual(f('bar'), 'foobar')
f = PRTR('s/bar/foo\0/')
self.assertEqual(f('bar'), 'foobar')
f = PRTR(r's/bar/foo\0/')
self.assertEqual(f('bar'), 'foobar')

def testMultipleReplacer(self):
replacer = utils.str.MultipleReplacer({'foo': 'bar', 'a': 'b'})
Expand Down