Browse Source

working escaped_semicolons=false w/tests

pull/1253/head
Ross McFarland 7 months ago
parent
commit
777a1a655a
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
5 changed files with 68 additions and 3 deletions
  1. +4
    -0
      .changelog/7a30ee9fb9dd433c9181ddd5628e5cd3.md
  2. +8
    -3
      octodns/provider/yaml.py
  3. +8
    -0
      tests/config-semis/escaped.semis.yaml
  4. +9
    -0
      tests/config-semis/unescaped.semis.yaml
  5. +39
    -0
      tests/test_octodns_provider_yaml.py

+ 4
- 0
.changelog/7a30ee9fb9dd433c9181ddd5628e5cd3.md View File

@ -0,0 +1,4 @@
---
type: minor
---
Add unescaped semicolons support to YamlProvider

+ 8
- 3
octodns/provider/yaml.py View File

@ -334,11 +334,16 @@ class YamlProvider(BaseProvider):
data = [data]
for d in data:
_type = d.get('type')
if not self.escaped_semicolons and _type in ('SPF', 'TXT'):
if not self.escaped_semicolons and _type in (
'SPF',
'TXT',
):
if 'value' in d:
d['value'] = d[''].replace(';', '\\;')
d['value'] = d['value'].replace(';', '\\;')
if 'values' in d:
d['values'] = [v.replace(';', '\\;') for v in d['values']]
d['values'] = [
v.replace(';', '\\;') for v in d['values']
]
if 'ttl' not in d:
d['ttl'] = self.default_ttl
record = Record.new(


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

@ -0,0 +1,8 @@
---
one:
type: TXT
value: This has a semi-colon\; that is escaped.
two:
type: TXT
values:
- This has a semi-colon too\; that is escaped.

+ 9
- 0
tests/config-semis/unescaped.semis.yaml View File

@ -0,0 +1,9 @@
---
one:
type: TXT
value: This has a semi-colon; that isn't escaped.
two:
type: TXT
values:
- This has a semi-colon too; that isn't escaped.
- ;

+ 39
- 0
tests/test_octodns_provider_yaml.py View File

@ -471,6 +471,45 @@ xn--dj-kia8a:
# make sure that we get the idna one back
self.assertEqual(idna, provider._zone_sources(zone))
def test_unescaped_semicolons(self):
source = YamlProvider(
'test',
join(dirname(__file__), 'config-semis'),
escaped_semicolons=False,
)
zone = Zone('unescaped.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,
)
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,
# )
class TestSplitYamlProvider(TestCase):
def test_list_all_yaml_files(self):


Loading…
Cancel
Save