Where do those two extra backslashes in front of the slash come from? Is this intended?
Thanks,
Leslie
On Tue, Jun 16, 2009 at 7:38 PM, Leslie P. Polzersky@viridian-project.de wrote:
Where do those two extra backslashes in front of the slash come from? Is this intended?
Thanks,
Leslie
Json allows / in strings, but if I am reading the diagram on json.org correctly prefers that it is prefixed by a backslash like this / . Probably prefered, because why would it be in the list of backslashed characters otherwise? See the mentioning about solidus in the string diagram. I don't really know why.
And the first backslash is the lisp backslash for the backslash character. So it is valid JSON, and probably prefered to /.
/Henrik
Henrik Hjelte wrote:
Json allows / in strings, but if I am reading the diagram on json.org correctly prefers that it is prefixed by a backslash like this / . Probably prefered, because why would it be in the list of backslashed characters otherwise? See the mentioning about solidus in the string diagram. I don't really know why.
Curious. Thanks for explaining, I will change the Weblocks tests to match this new output then.
Leslie
On Tue, Jun 16, 2009 at 10:41 PM, Henrik Hjeltehenrik@evahjelte.com wrote:
On Tue, Jun 16, 2009 at 7:38 PM, Leslie P. Polzersky@viridian-project.de wrote:
Where do those two extra backslashes in front of the slash come from? Is this intended?
Json allows / in strings, but if I am reading the diagram on json.org correctly prefers that it is prefixed by a backslash like this / . Probably prefered, because why would it be in the list of backslashed characters otherwise? See the mentioning about solidus in the string diagram. I don't really know why.
The most plausible explanation is that a JavaScript embedded in an HTML page can not include the sequence of characters LESS-THAN SIGN, SOLIDUS: per HTML 4.01 § 18.2.1, the contents of a SCRIPT element is CDATA which means (§ 6.2) that in the following text no markup is interpreted—up to the first occurence of “</”. Hence, if you'd want to put a literal string with a closing tag in your embedded script you'd have to somehow avoid that sequence. Escaping the solidus with the backslash seems one of the most unobtrusive means to do that. The same rationale applies in any case where one sends JSON embedded in a well-formed SGML document.
As to why ENCODE-JSON chooses to print the escape backslash where it is not required to: quite simply, such implementation resulted in more concise code with less special cases.
Yours, - B. Smilga.