From: Bob Halley Date: Wed, 1 Jun 2016 13:15:35 +0000 (-0700) Subject: Fix problems with escaping in quoted strings and names. X-Git-Tag: v1.15.0~47 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9a8f6fe738ee1b8b3388716754751e1b74455e66;p=thirdparty%2Fdnspython.git Fix problems with escaping in quoted strings and names. [issue #168] --- diff --git a/dns/name.py b/dns/name.py index 2a74694c..7a874b82 100644 --- a/dns/name.py +++ b/dns/name.py @@ -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() diff --git a/dns/rdata.py b/dns/rdata.py index 824731c7..97581977 100644 --- a/dns/rdata.py +++ b/dns/rdata.py @@ -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