From cec586beb61ea9303492f52db7ca44a2f841bfa1 Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Thu, 23 Jul 2020 19:21:16 -0700 Subject: [PATCH] Allow an escaped newline in a quoted string. --- dns/tokenizer.py | 2 +- tests/test_rdata.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/dns/tokenizer.py b/dns/tokenizer.py index 2a13e0f2..bef720b6 100644 --- a/dns/tokenizer.py +++ b/dns/tokenizer.py @@ -423,7 +423,7 @@ class Tokenizer: token += c has_escape = True c = self._get_char() - if c == '' or c == '\n': + if c == '' or (c == '\n' and not self.quoting): raise dns.exception.UnexpectedEnd token += c if token == '' and ttype != QUOTED_STRING: diff --git a/tests/test_rdata.py b/tests/test_rdata.py index 40f6f8da..ca509b89 100644 --- a/tests/test_rdata.py +++ b/tests/test_rdata.py @@ -459,6 +459,14 @@ class RdataTestCase(unittest.TestCase): self.assertEqual(mx, expected_mx) self.assertIsNone(mx.rdcomment) + def test_escaped_newline_in_quoted_string(self): + rd = dns.rdata.from_text('in', 'txt', '"foo\\\nbar"') + self.assertEqual(rd.strings, (b'foo\nbar',)) + self.assertEqual(rd.to_text(), '"foo\\010bar"') + + def test_escaped_newline_in_nonquoted_string(self): + with self.assertRaises(dns.exception.UnexpectedEnd): + dns.rdata.from_text('in', 'txt', 'foo\\\nbar') if __name__ == '__main__': unittest.main() -- 2.47.3