]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Fix problems with escaping in quoted strings and names.
authorBob Halley <halley@dnspython.org>
Wed, 1 Jun 2016 13:15:35 +0000 (06:15 -0700)
committerBob Halley <halley@dnspython.org>
Wed, 1 Jun 2016 13:15:35 +0000 (06:15 -0700)
[issue #168]

dns/name.py
dns/rdata.py

index 2a74694ccba3f59800bf4a808cdfb75205724940..7a874b8242a7e8f53cf826b760889f902c27b378 100644 (file)
@@ -105,11 +105,10 @@ def _escapify(label, unicode_mode=False):
         if isinstance(label, text_type):
             label = label.encode()
         for c in bytearray(label):
-            packed = struct.pack('!B', c).decode()
             if c in _escaped:
-                text += '\\' + packed
+                text += '\\' + chr(c)
             elif c > 0x20 and c < 0x7F:
-                text += packed
+                text += chr(c)
             else:
                 text += '\\%03d' % c
         return text.encode()
index 824731c7eea183a8b2599fe26661cb5a6add2fa1..975819778b64c6fb79ce54187168ee7751748042 100644 (file)
@@ -75,11 +75,7 @@ def _base64ify(data, chunksize=_base64_chunksize):
                       for i
                       in range(0, len(line), chunksize)]).decode()
 
-__escaped = {
-    '"': True,
-    '\\': True,
-}
-
+__escaped = bytearray(b'"\\')
 
 def _escapify(qstring):
     """Escape the characters in a quoted string which need it.
@@ -97,11 +93,10 @@ def _escapify(qstring):
 
     text = ''
     for c in qstring:
-        packed = struct.pack('!B', c).decode()
-        if packed in __escaped:
-            text += '\\' + packed
+        if c in __escaped:
+            text += '\\' + chr(c)
         elif c >= 0x20 and c < 0x7F:
-            text += packed
+            text += chr(c)
         else:
             text += '\\%03d' % c
     return text