-
Notifications
You must be signed in to change notification settings - Fork 31
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
Comments
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
it all seems to work like I'd expect. Are you using the latest version? Maybe I'm missing something? |
json5.loads('{a:"a\/"}') Sorry, bug git edit translate \/ as / |
import json5
print(json5.loads(r'{a:"a\/"}'))ValueError Traceback (most recent call last) ~/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) ValueError: :1 Unexpected "/" at column 7 |
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? |
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. |
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() $
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() $
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. |
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),`
The text was updated successfully, but these errors were encountered: