masaccio/compact-json

Data corruption when padding

rrthomas opened this issue · 3 comments

Given the input

[ "seq", [ "if", [ "=", "i", [ "prop", "length", "l" ] ], [ "return", "l" ] ] ]

compact-json produces:

[
    "seq", 
    [
        [                                        ], 
        [ "="     , "i", ["prop", "length", "l"] ], 
        [ "return", "l"                          ]
    ]
]

where the string "if" has been replaced with an empty list.

If in format_list I comment out the call to self.format_table_list_list, then the problem does not occur (but obviously the list is not padded either).

The JsonValueKind enum had identical values for string and list. Replaced explicit values with auto(). The formatting doesn't line up the elements as the first element of the list isn't a list itself:

[
    "seq", 
    [
        "if", 
        [ "=", "i", [ "prop", "length", "l" ] ], 
        [ "return", "l" ]
    ]
]

Thanks very much for the fix and release!