From 9a8f6fe738ee1b8b3388716754751e1b74455e66 Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Wed, 1 Jun 2016 06:15:35 -0700 Subject: [PATCH] Fix problems with escaping in quoted strings and names. [issue #168] --- dns/name.py | 5 ++--- dns/rdata.py | 13 ++++--------- 2 files changed, 6 insertions(+), 12 deletions(-) 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 -- 2.47.3