Browse Source

Double escaped semi-colon validation & tests

pull/1253/head
Ross McFarland 7 months ago
parent
commit
5c2e5d5a1a
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
5 changed files with 23 additions and 15 deletions
  1. +4
    -0
      .changelog/85710a9264524662becdc7e52e71e241.md
  2. +3
    -0
      octodns/record/chunked.py
  3. +1
    -0
      tests/config-semis/escaped.semis.yaml
  4. +9
    -15
      tests/test_octodns_provider_yaml.py
  5. +6
    -0
      tests/test_octodns_record_chunked.py

+ 4
- 0
.changelog/85710a9264524662becdc7e52e71e241.md View File

@ -0,0 +1,4 @@
---
type: minor
---
Add validation to TXT records to check for double escaped semi-colons

+ 3
- 0
octodns/record/chunked.py View File

@ -44,6 +44,7 @@ class _ChunkedValuesMixin(ValuesMixin):
class _ChunkedValue(str):
_unescaped_semicolon_re = re.compile(r'\w;')
_double_escaped_semicolon_re = re.compile(r'\\\\;')
@classmethod
def parse_rdata_text(cls, value):
@ -62,6 +63,8 @@ class _ChunkedValue(str):
for value in data:
if cls._unescaped_semicolon_re.search(value):
reasons.append(f'unescaped ; in "{value}"')
if cls._double_escaped_semicolon_re.search(value):
reasons.append(f'double escaped ; in "{value}"')
try:
value.encode('ascii')
except UnicodeEncodeError:


+ 1
- 0
tests/config-semis/escaped.semis.yaml View File

@ -6,3 +6,4 @@ two:
type: TXT
values:
- This has a semi-colon too\; that is escaped.
- \;

+ 9
- 15
tests/test_octodns_provider_yaml.py View File

@ -15,6 +15,7 @@ from octodns.idna import idna_encode
from octodns.provider import ProviderException
from octodns.provider.yaml import SplitYamlProvider, YamlProvider
from octodns.record import Create, NsValue, Record, ValuesMixin
from octodns.record.exception import ValidationError
from octodns.zone import SubzoneRecordException, Zone
@ -494,21 +495,14 @@ xn--dj-kia8a:
)
zone = Zone('escaped.semis.', [])
source.populate(zone)
self.assertEqual(2, len(zone.records))
one = next(r for r in zone.records if r.name == 'one')
self.assertTrue(one)
# self.assertEqual(
# ["This has a semi-colon\\; that isn't escaped."], one.values
# )
two = next(r for r in zone.records if r.name == 'two')
self.assertTrue(two)
# self.assertEqual(
# ["This has a semi-colon too\\; that isn't escaped.", '\\;'],
# two.values,
# )
with self.assertRaises(ValidationError) as ctx:
source.populate(zone)
self.assertEqual(
[
'double escaped ; in "This has a semi-colon\\\\; that is escaped."'
],
ctx.exception.reasons,
)
class TestSplitYamlProvider(TestCase):


+ 6
- 0
tests/test_octodns_record_chunked.py View File

@ -59,6 +59,12 @@ class TestChunkedValue(TestCase):
_ChunkedValue.validate('hello; world', 'TXT'),
)
# double escaped ;
self.assertEqual(
['double escaped ; in "hello\\\\; world"'],
_ChunkedValue.validate('hello\\\\; world', 'TXT'),
)
# non-asci
self.assertEqual(
['non ASCII character in "v=spf1 –all"'],


Loading…
Cancel
Save