Nykakin / chompjs

Parsing JavaScript objects into Python data structures
MIT License
198 stars 11 forks source link

Error when parsing function value without a comma #58

Closed every-time closed 9 months ago

every-time commented 10 months ago
src = '''
    {
        a: my_func
    }
'''

print(chompjs.parse_js_object(src))

Results in: json.decoder.JSONDecodeError: Invalid control character

Whereas each of the following works and results in: {'a': 'my_func'}

src = '''
    {
        a: my_func,
    }
'''

print(chompjs.parse_js_object(src))

Note the trailing comma in the example above.

src = '''
    {
        a: my_func
    }
'''

print(chompjs.parse_js_object(src.replace('\t', '').replace('\n', '')))
src = '''
    {
        a: my_func}
'''

print(chompjs.parse_js_object(src))

There are various combinations to try. I think from my brief testing, a tab or a newline after a function value without a comma results in an error. In other words, a function value either has to be immediately followed by a comma, space, or a closing bracket.

Nykakin commented 10 months ago

Thanks for reporting!

Care to stress-test the fix in #59 before I merge and release it?

every-time commented 10 months ago

I'm unable to thoroughly test it now but it looks good at a glance.

I appreciate the super quick response!