diff options
| author | Bob Halley <halley@dnspython.org> | 2020-07-23 19:21:16 -0700 |
|---|---|---|
| committer | Bob Halley <halley@dnspython.org> | 2020-07-23 19:21:16 -0700 |
| commit | cec586beb61ea9303492f52db7ca44a2f841bfa1 (patch) | |
| tree | 1482a03a721b83001bbbc5c0135414bc9cba4567 | |
| parent | d743fc42dac24f1427237d40892fdf40e09bf575 (diff) | |
| download | dnspython-cec586beb61ea9303492f52db7ca44a2f841bfa1.tar.gz | |
Allow an escaped newline in a quoted string.
| -rw-r--r-- | dns/tokenizer.py | 2 | ||||
| -rw-r--r-- | tests/test_rdata.py | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/dns/tokenizer.py b/dns/tokenizer.py index 2a13e0f..bef720b 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 40f6f8d..ca509b8 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() |
