You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Any idea of what should be the correct behaviour here?
it should fallback to ascii string....
as for print, try it with a file (or network stream), works fine:
>>>foo= {"foo": "my cool string with \ud80d in the middle of it"}
>>>withopen("somefile.json", "w") asopenjson:
... print(json.dumps(foo), file=openjson)
...
>>>withopen("somefile.json", "r") asopenjson:
... print(openjson.read(), end="")
...
{"foo": "my cool string with \ud80d in the middle of it"}
>>>
Option (a) might be helpful when doing low-level autopsies on JSON files but passing invalid characters along inside your application is a big problem, e.g. see encode/django-rest-framework#7026 for how this would cause "error 500" eventually during database access with the Django REST Framework until recently.
Any idea of what should be the correct behaviour here?
Please keep detecting and rejecting single surrogates as invalid characters.
Besides improvements in speed, it's a core feature of python-rapidjson over stdlib json.
I left this open for the "fallback to ASCII" desired behavior. I'm surely not going to tweak RJ for that, though.
I don't see anything at #81 (comment) that I would consider "falling back to ASCII". I see escaping during JSON encoding and unescaping during JSON decoding. Could you elaborate?
Activity
a-tal commentedon Sep 29, 2017
loadsalso fails:kenrobbins commentedon Sep 29, 2017
The segfault isn't good, but the loads is expected behavior in RapidJSON:
https://github.com/Tencent/rapidjson/blob/b45c5408d18e491d8d4c158cbbff5a805089500c/include/rapidjson/reader.h#L1021-L1028
https://github.com/Tencent/rapidjson/blob/52682115fb223518474271023202c904a34865b4/include/rapidjson/error/en.h#L52
lelit commentedon Sep 29, 2017
Interesting:
lelit commentedon Sep 29, 2017
Any idea of what should be the correct behaviour here?
Fix crash when dealing with surrogate pairs
kenrobbins commentedon Sep 29, 2017
What you have in the commit seems fine to me. If we want different behavior, seems like we'd have to customize RapidJSON, no?
a-tal commentedon Sep 29, 2017
it should fallback to ascii string....
as for print, try it with a file (or network stream), works fine:
lelit commentedon Sep 30, 2017
I'd be curious to know why RapidJSON opted for not handling those codepoints. Does the JSON standard say anything about?
lelit commentedon Jan 13, 2018
Also
yajldoes something debatable:itamarst commentedon Feb 19, 2019
So it seems like the actual coredump is fixed? Does this issue need to be open or can it be closed?
lelit commentedon Feb 20, 2019
Yes, the crash has been cured.
I left this open for the "fallback to ASCII" desired behavior. I'm surely not going to tweak RJ for that, though.
hartwork commentedon Feb 20, 2020
ECMA-404 says:
So it's valid JSON with single surrogate characters in. The processor has two options in my view:
U+FFFD, three different known approachesOption (a) might be helpful when doing low-level autopsies on JSON files but passing invalid characters along inside your application is a big problem, e.g. see encode/django-rest-framework#7026 for how this would cause "error 500" eventually during database access with the Django REST Framework until recently.
I gave a talk about this problem just a few days ago, the slides are up at https://github.com/hartwork/slides_python_json_emoji_crash_story/releases if you're interested.
Please keep detecting and rejecting single surrogates as invalid characters.
Besides improvements in speed, it's a core feature of
python-rapidjsonover stdlibjson.I don't see anything at #81 (comment) that I would consider "falling back to ASCII". I see escaping during JSON encoding and unescaping during JSON decoding. Could you elaborate?
lelit commentedon Feb 22, 2020
Thanks. Does this mean that in your opinion this issue should be considered as done?
Uhm, this tricked me... in that comment, Adam answered to my "request for opinion" about the correct behaviour:
I think that means the surrogate unicode would be basically ignored, "left as is", not escaped-unescaped... or am I missing the point?
hartwork commentedon Feb 23, 2020
I believe so, yes: I was able to reproduce the segfault with 0.2.4 but neither with 0.2.5 nor with 0.9.1 since they come with your fix 6f12323.
hartwork commentedon Feb 23, 2020
PS: For
{"foo": chr(0xd80d)}functiondumpshas two options:{"foo": "\ud80d"}to fileUnicodeEncodeErroras-is: