# HG changeset patch # User Tero Marttila # Date 1425049998 -7200 # Node ID 90a0790adf8af0a970c8561fcb2f9cbfa8bba18a # Parent 585fe8171ac63dae773afa4bd8202166c2c8f6a9 pvl.dns: quote ZoneDirective arguments only on output if required diff -r 585fe8171ac6 -r 90a0790adf8a pvl/dns/tests.py --- a/pvl/dns/tests.py Fri Feb 27 17:06:54 2015 +0200 +++ b/pvl/dns/tests.py Fri Feb 27 17:13:18 2015 +0200 @@ -215,6 +215,6 @@ " NS bar", "foo A 192.0.2.1", "bar A 192.0.2.2", - "$INCLUDE \".../includes/test\"", + "$INCLUDE .../includes/test", ]) diff -r 585fe8171ac6 -r 90a0790adf8a pvl/dns/zone.py --- a/pvl/dns/zone.py Fri Feb 27 17:06:54 2015 +0200 +++ b/pvl/dns/zone.py Fri Feb 27 17:13:18 2015 +0200 @@ -30,14 +30,17 @@ Quote a value for inclusion into TXT record. >>> print zone_quote("foo") - "foo" + foo >>> print zone_quote("foo\\bar") "foo\\bar" >>> print zone_quote("foo \"bar\" quux") "foo \"bar\" quux" """ - return u'"' + field.replace('\\', '\\\\').replace('"', '\\"') + u'"' + if any(c.isspace() or c == '\\' for c in field): + return u'"' + field.replace('\\', '\\\\').replace('"', '\\"') + u'"' + else: + return field class ZoneLine (object) : @@ -226,9 +229,9 @@ """ if origin: - return cls.build('INCLUDE', zone_quote(path), origin, **opts) + return cls.build('INCLUDE', path, origin, **opts) else: - return cls.build('INCLUDE', zone_quote(path), **opts) + return cls.build('INCLUDE', path, **opts) def __init__ (self, directive, arguments, comment=None, line=None, origin=None): """ @@ -258,7 +261,7 @@ return u"${directive}\t{arguments}{comment}".format( directive = self.directive, - arguments = '\t'.join(self.arguments), + arguments = '\t'.join(zone_quote(argument) for argument in self.arguments), comment = comment, )