Selaa lähdekoodia

Improve parsing of string literals

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@42484 15284696-431f-4ddb-bdfa-cd5b030d7da7
Glynn Clements 15 vuotta sitten
vanhempi
commit
34368c69cd
1 muutettua tiedostoa jossa 6 lisäystä ja 1 poistoa
  1. 6 1
      lib/python/ctypes/ctypesgencore/parser/pplexer.py

+ 6 - 1
lib/python/ctypes/ctypesgencore/parser/pplexer.py

@@ -60,7 +60,12 @@ class StringLiteral(str):
         try:
             value = value[1:-1].decode('string_escape')
         except ValueError, e:
-            raise ValueError("invalid \\x escape in %s" % value)
+            try:
+                value = re.sub(r'\\x([0-9a-fA-F])(?![0-9a-fA-F])',
+                               r'\x0\1',
+                               value[1:-1]).decode('string_escape')
+            except ValueError, e:
+                raise ValueError("invalid \\x escape in %s" % value)
         return str.__new__(cls, value)
 
 # --------------------------------------------------------------------------