Nykakin / chompjs

Parsing JavaScript objects into Python data structures
MIT License
197 stars 11 forks source link

Handle escaped quotations correctly #6

Closed Nykakin closed 4 years ago

Nykakin commented 4 years ago

json.loads treats \\' as an invalid escape:

>>> json.loads('''{"a": "\\'"}''')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.7/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Invalid \escape: line 1 column 8 (char 7)

So the library should translate {"a": "\\'"} to {"a": "'"}