Skip to content

Commit

Permalink
added support for escaping TXT record content
Browse files Browse the repository at this point in the history
  • Loading branch information
metagriffin committed Dec 3, 2014
1 parent 86a6634 commit d5bb9fc
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pdns/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import sys
import six
import dns.zone
import dns.rdata
import difflib
import re
import blessings
Expand Down Expand Up @@ -87,6 +88,15 @@ def reldom(domain):
domain = domain[:-1]
return domain

#------------------------------------------------------------------------------
def escapeContent(text):
if not text:
return text
# todo: `dns.rdata._escapify` should really be doing this detection for me...
if ';' not in text and ' ' not in text and '"' not in text:
return text
return '"' + dns.rdata._escapify(text) + '"'

#------------------------------------------------------------------------------
def downloadZone(ctxt):
# TODO: i should really be building this from dns.zone.* calls...
Expand All @@ -96,6 +106,9 @@ def downloadZone(ctxt):
fmt = RECORDFMTS.get(record.Type, RECORDFMTS.get('*'))
record.Content = ' '.join([
absdom(comp) for comp in record.Content.split()])
# todo: is TXT really the only record type?...
if record.Type == 'TXT':
record.Content = escapeContent(record.Content)
lines.append(fmt.format(
name = absdom(record.Name),
ttl = record.TimeToLive,
Expand Down

0 comments on commit d5bb9fc

Please sign in to comment.