Bug
dumps() serializes an empty string value as k = \n (nothing after the =). The parser cannot recover the empty string from this output — the token after = is effectively absent, causing incorrect parsing or a ParserError.
The round-trip loads(dumps(data)) == data fails for any dict containing an empty string value.
Reproducer
import structprop
out = structprop.dumps({"k": ""})
print(repr(out)) # 'k = \n'
back = structprop.loads(out)
print(back) # {'k': <next key's value or ParserError>}
Root cause
_escape() only checks for space and tab characters. An empty string contains neither, so it is returned as-is, producing a bare empty token.
Fix
_escape should return '""' for empty strings:
def _escape(k):
if not k:
return '""'
for ch in _ESCAPE_CHARACTERS:
if ch in k:
return '"%s"' % (k,)
return k
Bug
dumps()serializes an empty string value ask = \n(nothing after the=). The parser cannot recover the empty string from this output — the token after=is effectively absent, causing incorrect parsing or aParserError.The round-trip
loads(dumps(data)) == datafails for any dict containing an empty string value.Reproducer
Root cause
_escape()only checks for space and tab characters. An empty string contains neither, so it is returned as-is, producing a bare empty token.Fix
_escapeshould return'""'for empty strings: