Skip to content

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

Closed

Description

@gonvaled

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)

Activity

  1. paskal commented on Dec 2, 2015

    @paskal

    Stepped onto it too.

  2. vaidik commented on Jul 7, 2019

    @vaidik
    Owner

    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.

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