8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 26af9e4 commit f0a3d89Copy full SHA for f0a3d89
tornado/escape.py
@@ -54,7 +54,13 @@ def xhtml_unescape(value):
54
55
def json_encode(value):
56
"""JSON-encodes the given Python object."""
57
- return _json_encode(value)
+ # JSON permits but does not require forward slashes to be escaped.
58
+ # This is useful when json data is emitted in a <script> tag
59
+ # in HTML, as it prevents </script> tags from prematurely terminating
60
+ # the javscript. Some json libraries do this escaping by default,
61
+ # although python's standard library does not, so we do it here.
62
+ # http://stackoverflow.com/questions/1580647/json-why-are-forward-slashes-escaped
63
+ return _json_encode(value).replace("</", "<\\/")
64
65
66
def json_decode(value):
0 commit comments