Merge pull request #3754 from jtraglia/add-0x-quotes

Encode zero-length hex-strings with quotes
This commit is contained in:
Justin Traglia 2024-10-23 09:37:33 -05:00 committed by GitHub
commit 60343aeeaa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 0 deletions

View File

@ -65,7 +65,14 @@ def get_default_yaml():
def _represent_none(self, _):
return self.represent_scalar('tag:yaml.org,2002:null', 'null')
def _represent_str(self, data):
if data.startswith("0x"):
# Without this, a zero-byte hex string is represented without quotes.
return self.represent_scalar('tag:yaml.org,2002:str', data, style="'")
return self.represent_str(data)
yaml.representer.add_representer(type(None), _represent_none)
yaml.representer.add_representer(str, _represent_str)
return yaml