Skip to main content

Bug Tracker

Side navigation

#13602 closed bug (notabug)

Opened March 12, 2013 03:16PM UTC

Closed March 12, 2013 03:25PM UTC

Last modified March 12, 2013 03:49PM UTC

parseJSON() chokes on embedded tab

Reported by: jquery@compressedtime.com Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:
Description

$.parseJSON('[{"name":"a\\tb"}]');

results in

SyntaxError: Unexpected token

Attachments (0)
Change History (3)

Changed March 12, 2013 03:25PM UTC by dmethvin comment:1

resolution: → notabug
status: newclosed

The strings in JSON can't have control characters, as laid out pretty clearly in the diagrams at http://json.org. A tab is a control character. A "\\t" in a JavaScript literal string is converted to a tab. If some tool had created that JSON it did not encode it correctly.

Changed March 12, 2013 03:45PM UTC by anonymous comment:2

pphp json_encode() will generate it.

And jsonlint.com will validate it.

Not that those are necessarily authoritative, but something to consider.

(P.S. I tried to paste some php+javascript code, but cannot. Is there a jsfiddle-like site for php?)

Changed March 12, 2013 03:49PM UTC by dmethvin comment:3

At some point your code is letting something change "\\t" to a tab character. Please ask for help on a forum. This isn't a jQuery bug.