string with bslash · Issue #23 · dpranke/pyjson5 · GitHub
Skip to content

string with bslash #23

Closed
Closed

Description

@sloanyyc

son5.loads('{a:"a/"}')
ValueError: :1 Unexpected "/" at column 7
such as 'http://domain/' can't jsonfiy

temp fix
`# comment /usr/local/lib/python3.7/site-packages/json5/parser.py

def sqchar__c2(self):
self._push('sqchar__c2')
self._seq([# lambda: self._not(self.bslash),
lambda: self._not(self.squote),

def dqchar__c2(self):
self._push('dqchar__c2')
self._seq([# lambda: self._not(self.bslash), # this line
lambda: self._not(self.dquote),`

Activity

  1. dpranke commented on Feb 25, 2019

    @dpranke
    Owner

    Hi,

    Thanks for the bug report. However, I don't think I understand what you're reporting.

    You said "blash" in the subject, but your example is using forward slashes.

    Also, if I test the example you give with the latest version of

    $ python3
    >>> import json5
    >>> json5.VERSION
    '0.6.1'
    >>> print(json5.loads(r'{a:"a/"}'))
    {'a': 'a/'}
    >>> print(json5.loads(r'{a:"a\"}'))
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/src/pyjson5/json5/lib.py", line 59, in loads
        raise ValueError(err)
    ValueError: <string>:1 Unexpected end of input at column 9
    >>> print(json5.loads(r'{a:"a\\"}'))
    {'a': 'a\\'}
    >>> ^D
    

    it all seems to work like I'd expect. Are you using the latest version? Maybe I'm missing something?

  2. sloanyyc commented on Feb 26, 2019

    @sloanyyc
    Author

    json5.loads('{a:"a\/"}')
    ValueError: :1 Unexpected "/" at column 7
    such as 'http://domain/' can't jsonfiy

    Sorry, bug git edit translate \/ as /

  3. sloanyyc commented on Feb 26, 2019

    @sloanyyc
    Author

    import json5
    json5.VERSION

    '0.6.1'

    print(json5.loads(r'{a:"a\/"}'))

    ValueError Traceback (most recent call last)
    in
    ----> 1 print(json5.loads(r'{a:"a\/"}'))

    ~/venv/lib/python3.7/site-packages/json5/lib.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook)
    57 ast, err, newpos = parser.parse()
    58 if err:
    ---> 59 raise ValueError(err)
    60
    61 def _fp_constant_parser(s):

    ValueError: :1 Unexpected "/" at column 7

  4. dpranke commented on Feb 26, 2019

    @dpranke
    Owner

    Ah, got it. Yes, that looks like a bug.

    Side note: I'm curious, are you tripping across this specific example, or is this a simplified version of something? Because in this case, I'd imagine you could just work around this by deleting the backslash?

  5. sloanyyc commented on Feb 26, 2019

    @sloanyyc
    Author

    I am using scrapy spider some web page . It contains js with json5 format. Got a lot of string like "http:\/\/abc\/". I don't sure json5 format deal with '\/'. With json5 parse is more comfortable.

  6. added 2 commits that reference this issue on Mar 8, 2019
  7. dpranke commented on Mar 8, 2019

    @dpranke
    Owner

    Thanks for the bug report. This should be fixed now on master, v0.6-dev, and in v0.6.2, newly pushed to PyPI.

    This also newly handles "\0" correctly, which it didn't before and which I noticed while digging into 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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions