The documentation states that parse_js_objects doesn't raise. This isn't necessarily true, as I've encountered some botched inputs that can raise ValueError:
>>> list(chompjs.parse_js_objects("\0"))
Traceback (most recent call last):
...
ValueError: embedded null character
UnicodeEncodeError can be raised on some inputs:
>>> next(chompjs.parse_js_objects('\ud83f'))
Traceback (most recent call last):
...
UnicodeEncodeError: 'utf-8' codec can't encode character '\ud83f' in position 0: surrogates not allowed
UnicodeEncodeError can be sometimes raised when unicode_escape=True is True:
>>> list(chompjs.parse_js_objects(chr(92), unicode_escape=False))
[]
>>> list(chompjs.parse_js_objects(chr(92), unicode_escape=True))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/mariusz/Documents/Projekty/chompjs/chompjs/chompjs.py", line 127, in parse_js_objects
string = _preprocess(string, unicode_escape)
File "/home/mariusz/Documents/Projekty/chompjs/chompjs/chompjs.py", line 10, in _preprocess
string = string.encode().decode('unicode_escape')
UnicodeDecodeError: 'unicodeescape' codec can't decode byte 0x5c in position 0: \ at end of string
Finally, trying to run:
$ python -c "import chompjs; next(chompjs.parse_js_objects('[{]'), None)"
This botched input sometimes raises UnicodeDecodeError, sometimes not.
The documentation states that
parse_js_objectsdoesn't raise. This isn't necessarily true, as I've encountered some botched inputs that can raiseValueError:UnicodeEncodeErrorcan be raised on some inputs:UnicodeEncodeErrorcan be sometimes raised whenunicode_escape=Trueis True:Finally, trying to run:
This botched input sometimes raises
UnicodeDecodeError, sometimes not.