Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A quote as the last character in a comment crashes the parser: #10

Closed
gonvaled opened this issue Jul 6, 2015 · 2 comments
Closed

A quote as the last character in a comment crashes the parser: #10

gonvaled opened this issue Jul 6, 2015 · 2 comments

Comments

@gonvaled
Copy link

gonvaled commented Jul 6, 2015

A quote as the last character in a comment (maybe followed by a space) will crash the parser:

{
    "a" : "b" # this is a quote: "
}
Traceback (most recent call last):
  File "xxx.py", line 8, in <module>
    print commentjson.loads(a)
  File ".../local/lib/python2.7/site-packages/commentjson/commentjson.py", line 63, in loads
    raise JSONLibraryException(e.message)
commentjson.commentjson.JSONLibraryException: JSON Library Exception

Exception thrown by JSON library (json): Expecting , delimiter: line 2 column 15 (char 16)

    Traceback (most recent call last):
      File ".../local/lib/python2.7/site-packages/commentjson/commentjson.py", line 61, in loads
        return json.loads('\n'.join(lines), **kwargs)
      File "/usr/lib/python2.7/json/__init__.py", line 338, in loads
        return _default_decoder.decode(s)
      File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
        obj, end = self.raw_decode(s, idx=_w(s, 0).end())
      File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
        obj, end = self.scan_once(s, idx)
    ValueError: Expecting , delimiter: line 2 column 15 (char 16)

This was difficult to find, specially because the line numbers reported do not make sense (they are line numbers after removing the comments, which does not correlate in the general case with the source file, specially if - like I do - you have lots of blank lines or lines with comments-only)

@paskal
Copy link

paskal commented Dec 2, 2015

Stepped onto it too.

@vaidik
Copy link
Owner

vaidik commented Jul 7, 2019

Sorry for getting around to this so late. I was not maintaining commentjson in between. Got really busy with my day job. I am trying to maintain this now regularly. So expect faster responses.

This is fixed. You can try the latest version of commentjson which addresses this and a lot of other unhandled cases like this.

@vaidik vaidik closed this as completed Jul 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants