]> granicus.if.org Git - python/commitdiff
Fix for literal null bytes -- these must be replaced by the four
authorGuido van Rossum <guido@python.org>
Thu, 19 Feb 1998 21:18:56 +0000 (21:18 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 19 Feb 1998 21:18:56 +0000 (21:18 +0000)
characters \, 0, 0, 0.

Lib/re.py

index 3fb9408367ea8543aaef0dbcbd3704e5a79c4d66..e67d142ff17c796115483dcba69215586091ffa7 100644 (file)
--- a/Lib/re.py
+++ b/Lib/re.py
@@ -66,8 +66,9 @@ def escape(pattern):
     alphanum=string.letters+'_'+string.digits
     for char in pattern:
        if char not in alphanum:
-           result.append('\\')
-       result.append(char)
+           if char == '\000': result.append(r'\000')
+           else: result.append('\\' + char)
+       else: result.append(char)
     return string.join(result, '')
 
 def compile(pattern, flags=0):