"line separator" (U+2028) breaks JSON

Richard Chonak <[email protected]>
Newsgroups gmane.comp.web.blogger.api
Message-ID <[email protected]>
SUMMARY:
JSON output containing the special character "line separator" (U+2028) is 
rejected as invalid Javascript.

SITUATION:
A document copied and pasted from a word-processor may contain the special 
character U+2028 (line separator).   

If a post contains that character, a Blogger API query for a list of recent 
posts will deliver a JSON object with the character, unchanged -- that is, 
not 'escaped'.
Browsers reject the object as invalid Javascript.

TO REPRODUCE THE PROBLEM:

(1)  Create a sample post with this content:

"start
(U+2028 goes here)
end"

(See the attached file small-sample.txt.)

Copy and paste that file into the Blogger post editor (HTML mode) and save.


(2) In a Blogger widget, I request a JSON object: 

<script 
src="http://bistropha.blogspot.com/feeds/posts/default?alt=json-in-script&callback=document.write"></script>

This should write the JSON object to the screen.

(3) View blog.  Execution of the widget fails with no error message.

This snapshot from the browser's Javascript console shows an excerpt from 
the JSON object, with the line separator character before and after "start".

The error message "Uncaught SyntaxError: Unexpected token ILLEGAL" is 
generated by that line of the JSON object.

<https://lh5.googleusercontent.com/-hkAqp6yl03k/U3XmC1Cg4LI/AAAAAAAABcE/S98YYCfC0T8/s1600/snapshot161.png>

(4) To check the JSON separately, I ran 

http://www.freeformatter.com/json-validator.html

with this URL:
http://bistropha.blogspot.com/feeds/posts/default?alt=json

If you need more information to reproduce the problem, feel free to contact 
me.

Thanks!



-- 
You received this message because you are subscribed to the Google Groups "Blogger Developer Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/bloggerdev.
For more options, visit https://groups.google.com/d/optout.
small-sample.txt (text/plain, 14 B)
start


end
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.