From cb49bfc57cbf68f0e31f0c2f541eb64a06463eca Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Sun, 26 Jul 2020 14:12:01 -0700 Subject: [PATCH] increase TXT coverage --- dns/rdtypes/txtbase.py | 5 ++++- tests/test_rdata.py | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/dns/rdtypes/txtbase.py b/dns/rdtypes/txtbase.py index 38c56011..6d0b6abe 100644 --- a/dns/rdtypes/txtbase.py +++ b/dns/rdtypes/txtbase.py @@ -65,7 +65,10 @@ class TXTBase(dns.rdata.Rdata): strings = [] for token in tok.get_remaining(): token = token.unescape_to_bytes() - if not (token.is_quoted_string() or token.is_identifier()): + # The 'if' below is always true in the current code, but we + # are leaving this check in in case things change some day. + if not (token.is_quoted_string() or + token.is_identifier()): # pragma: no cover raise dns.exception.SyntaxError("expected a string") if len(token.value) > 255: raise dns.exception.SyntaxError("string too long") diff --git a/tests/test_rdata.py b/tests/test_rdata.py index 82d150dd..8d9937e1 100644 --- a/tests/test_rdata.py +++ b/tests/test_rdata.py @@ -614,6 +614,15 @@ class RdataTestCase(unittest.TestCase): '20200101000000 2003010100000 ' + '2143 foo Ym9ndXM=') + def test_empty_TXT(self): + # hit too long + with self.assertRaises(dns.exception.SyntaxError): + dns.rdata.from_text('in', 'txt', '') + + def test_too_long_TXT(self): + # hit too long + with self.assertRaises(dns.exception.SyntaxError): + dns.rdata.from_text('in', 'txt', 'a' * 256) class UtilTestCase(unittest.TestCase): -- 2.47.3