Skip to content

dumps() does not quote values containing '=', producing output the parser misreads #18

Description

@anthonyoteri

Bug

dumps() does not quote string values that contain =. The resulting output is structurally ambiguous: the parser's lexer treats = as the assignment operator EQ, so a value like foo=bar is tokenized as three separate tokens (foo, EQ, bar) rather than a single value.

The round-trip loads(dumps(data)) == data fails for any value containing =.

Reproducer

import structprop
out = structprop.dumps({"k": "foo=bar"})
print(repr(out))   # 'k = foo=bar\n'
back = structprop.loads(out)
# ParserError or silently wrong result — 'bar' is parsed as a stray token

Root cause

_ESCAPE_CHARACTERS is defined as ' \t' — only space and tab. The = character is a special token in the lexer but is absent from the escape set.

Fix

Extend _ESCAPE_CHARACTERS (or the escape logic) to include all characters that the lexer treats as special: =, {, }, #, newline, and carriage return:

_ESCAPE_CHARACTERS = ' \t\n\r#{}='

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions