Bug Tracker

Modify

Ticket #8034 (closed bug: invalid)

Opened 3 years ago

Last modified 2 years ago

parseJSON() fails when special characters are passed in

Reported by: ievolve Owned by: rwaldron
Priority: low Milestone: 1.next
Component: core Version: 1.4.2
Keywords: Cc:
Blocking: Blocked by:

Description

I came across a situation where some oddly encoded characters cause the JSON parser to bomb. In my case it was the cancel character (0x18) that a user had submitted.

Worth noting that JSON parse that is at the link below will parse things just fine. Where JSON.parse() bombs just like the jQuery method.  https://github.com/douglascrockford/JSON-js/blob/master/json_parse.js

Code that contains the cancel character can be copied and pasted from here to relicate the issue. The bad character sits between the n and the s in the word "brains"  http://pastie.org/1485459

Change History

comment:1 Changed 3 years ago by ievolve

To see this bug in action see the example here:  http://jsfiddle.net/eBEeC/

Should note that the bug also occurs in 1.4.4 as well

Last edited 3 years ago by ievolve (previous) (diff)

comment:2 Changed 3 years ago by rwaldron

  • Owner set to rwaldron
  • Status changed from new to assigned
  • Component changed from unfiled to core

comment:3 Changed 3 years ago by rwaldron

We can test for these...

 http://jsfiddle.net/rwaldron/zP3NJ/8/

comment:4 Changed 3 years ago by jitter

  • Priority changed from undecided to low
  • Status changed from assigned to closed
  • Resolution set to invalid

This isn't a bug, the  JSON specification is clear about which characters need to be escaped in valid json.

2.5. Strings
[...]
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).

As U+0018 lies in this range, throwing an exception is the specified behavior of  jQuery.parseJSON.

Running your sample json through the  JSON validator also reveals that this is invalid json.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.