Skip to content

Commit

Permalink
Merge pull request #75 from octodns/handle-missing-content
Browse files Browse the repository at this point in the history
Fix bug in handling of empty strings/content on TXT records
  • Loading branch information
ross authored Jan 23, 2024
2 parents cf555c5 + 21d97c9 commit baf0730
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
as a source
* Support for auto-ttl without proxied as records can be configured that way,
see auto-ttl in README.md for more info
* Fix bug in handling of empty strings/content on TXT records

## v0.0.3 - 2023-09-20 - All the commits fit to release

Expand Down
4 changes: 3 additions & 1 deletion octodns_cloudflare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ def _data_for_TXT(self, _type, records):
return {
'ttl': self._ttl_data(records[0]['ttl']),
'type': _type,
'values': [r['content'].replace(';', '\\;') for r in records],
'values': [
r.get('content', '').replace(';', '\\;') for r in records
],
}

def _data_for_CAA(self, _type, records):
Expand Down
19 changes: 19 additions & 0 deletions tests/test_octodns_provider_cloudflare.py
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,25 @@ def test_srv(self):
list(srv_record_with_sub_contents)[0],
)

def test_txt(self):
provider = CloudflareProvider('test', 'email', 'token')

# single record w/content
data = provider._data_for_TXT(
'TXT', [{'ttl': 42, 'content': 'hello world'}]
)
self.assertEqual(
{'ttl': 42, 'type': 'TXT', 'values': ['hello world']}, data
)

# missing content, equivilent to empty from CF
data = provider._data_for_TXT('TXT', [{'ttl': 42}])
from pprint import pprint

pprint(data)

self.assertEqual({'ttl': 42, 'type': 'TXT', 'values': ['']}, data)

def test_alias(self):
provider = CloudflareProvider('test', 'email', 'token')

Expand Down

0 comments on commit baf0730

Please sign in to comment.