From: Bob Halley Date: Fri, 24 Jul 2020 02:21:16 +0000 (-0700) Subject: Allow an escaped newline in a quoted string. X-Git-Tag: v2.1.0rc1~148 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cec586beb61ea9303492f52db7ca44a2f841bfa1;p=thirdparty%2Fdnspython.git Allow an escaped newline in a quoted string. --- 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()