Only remove slashes when encode_html_chars = True
Check it out - https://github.com/esnme/ultrajson/pull/114
The JSON specification says that front slices should be hidden implicitly.
Here is the solution to do this in JSONEncoder itself. Itβs just that you create an ESCAPE SCENARIO and do the calculations in front of you and later do the encoding.
https://chromium.googlesource.com/external/googleappengine/python/+/dc33addea2da464ca07e869cb11832e1ae82da9d/lib/django/django/utils/simplejson/encoder.py
Hope this helps.
-
Adding to the above solution, there is another reason to avoid characters. As kay said, this gives us extra sleep. It prevents an attack. Thus, the solution above takes care of all the problems.
ESCAPE_DCT = { # escape all forward slashes to prevent </script> attack '/': '\\/', '\\': '\\\\', '"': '\\"', '\b': '\\b', '\f': '\\f', '\n': '\\n', '\r': '\\r', '\t': '\\t', }
bozzmob
source share