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

string with bslash #23

Closed
sloanyyc opened this issue Feb 25, 2019 · 6 comments
Closed

string with bslash #23

sloanyyc opened this issue Feb 25, 2019 · 6 comments

Comments

@sloanyyc
Copy link

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),`

@dpranke
Copy link
Owner

dpranke commented Feb 25, 2019

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?

@sloanyyc
Copy link
Author

sloanyyc commented Feb 26, 2019

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

Sorry, bug git edit translate \/ as /

@sloanyyc
Copy link
Author

sloanyyc commented Feb 26, 2019

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

@dpranke
Copy link
Owner

dpranke commented Feb 26, 2019

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?

@sloanyyc
Copy link
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.

dpranke added a commit that referenced this issue Mar 8, 2019
It turns out that unrecognized characters in escape sequences
should be tolerated and passed through. This change implements that and
also adds support for \0 in string literals:

    $ python3
    >>> import json5
    >>> json5.loads(r'"\/"')
    '/'
    >>> json5.loads(r'"\0"')
    '\x00'
    >>> quit()
    $
dpranke added a commit that referenced this issue Mar 8, 2019
It turns out that unrecognized characters in escape sequences
should be tolerated and passed through. This change implements that and
also adds support for \0 in string literals:

    $ python3
    >>> import json5
    >>> json5.loads(r'"\/"')
    '/'
    >>> json5.loads(r'"\0"')
    '\x00'
    >>> quit()
    $
@dpranke
Copy link
Owner

dpranke commented Mar 8, 2019

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.

@dpranke dpranke closed this as completed Mar 8, 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

2 participants