[issue23766] json.dumps: solidus ("/") should be escaped

Martin Panter report at bugs.python.org
Tue Mar 24 23:12:03 CET 2015


Martin Panter added the comment:

According to that RFC section, the forward solidus is allowed to be in an escape sequence, but it is also allowed unescaped:

“All Unicode characters may be placed within the quotation marks, except for the characters that must be escaped: quotation mark, reverse solidus, and the control characters (U+0000 through U+001F).”

. . .

unescaped = %x20-21 / %x23-5B / %x5D-10FFFF

In general, escaping the forward solidus is not needed, and is easier to read. Apparently this escaping is a workaround for embedding JSON inside a HTML <script> element, where the sequence “</” is not allowed, and HTML itself does not allow escaping: <http://www.w3.org/TR/html4/appendix/notes.html#h-B.3.2>. In that case, JSON like {markup: "<i>italic<\/i>"} would be escaped, but most cases still do not need escaping, such as {url: "http://example.net/"}.

----------
nosy: +vadmium

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23766>
_______________________________________


More information about the Python-bugs-list mailing list