Browse Source

idna_decode barfs on .., so needs a work-around

pull/1205/head
Ross McFarland 1 year ago
parent
commit
08de84078e
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
3 changed files with 20 additions and 3 deletions
  1. +4
    -1
      octodns/idna.py
  2. +4
    -2
      tests/test_octodns_idna.py
  3. +12
    -0
      tests/test_octodns_record.py

+ 4
- 1
octodns/idna.py View File

@ -45,7 +45,10 @@ def idna_decode(name):
if name.startswith('*'):
# idna.decode doesn't like the *
return f'*.{_decode(name[2:])}'
return _decode(name)
# idna.decode doesn't like .. so we stick a unique placeholder
# anywhere we see it and then remove it again afterwards.
name = name.replace('..', '.pl-a-ce--hold-e--r.')
return _decode(name).replace('.pl-a-ce--hold-e--r.', '..')
except _IDNAError as e:
raise IdnaError(e)
# not idna, just return as-is


+ 4
- 2
tests/test_octodns_idna.py View File

@ -66,8 +66,10 @@ class TestIdna(TestCase):
self.assertEqual('Empty Label', str(ctx.exception))
with self.assertRaises(IdnaError) as ctx:
idna_decode('xn--djvu-1na6c..com.')
self.assertEqual('Empty Label', str(ctx.exception))
idna_decode('xn--djvu-1na6c.something-.com.')
self.assertEqual(
'Label must not start or end with a hyphen', str(ctx.exception)
)
class TestIdnaDict(TestCase):


+ 12
- 0
tests/test_octodns_record.py View File

@ -692,6 +692,18 @@ class TestRecordValidation(TestCase):
reason,
)
# double dots in idna names
with self.assertRaises(ValidationError) as ctx:
Record.new(
self.zone,
'niño.',
{'ttl': 301, 'type': 'A', 'value': '1.2.3.4'},
)
reason = ctx.exception.reasons[0]
self.assertEqual(
'invalid name, double `.` in "niño..unit.tests."', reason
)
# no ttl
with self.assertRaises(ValidationError) as ctx:
Record.new(self.zone, '', {'type': 'A', 'value': '1.2.3.4'})


Loading…
Cancel
Save