]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Allow an escaped newline in a quoted string.
authorBob Halley <halley@dnspython.org>
Fri, 24 Jul 2020 02:21:16 +0000 (19:21 -0700)
committerBob Halley <halley@dnspython.org>
Fri, 24 Jul 2020 02:21:16 +0000 (19:21 -0700)
dns/tokenizer.py
tests/test_rdata.py

index 2a13e0f2edaf49dfddc6df206270eedee16dc6e1..bef720b64548bc1221cd27fc0bdcebbbc7e2037a 100644 (file)
@@ -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:
index 40f6f8da023c79cfa09fba7e5d441f70ca608c5f..ca509b893370af3f0370c7290a6b59979884cb74 100644 (file)
@@ -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()