Skip to main content

Bug Tracker

Side navigation

#6577 closed bug (fixed)

Opened May 17, 2010 12:58PM UTC

Closed November 21, 2010 10:34PM UTC

Last modified January 21, 2011 02:55PM UTC

jQuery.jsonParse is freezing FireFox and Chrome when parsing non-breaking whitespace (0xA0)

Reported by: maggrave Owned by:
Priority: high Milestone: 1.4.4
Component: ajax Version: 1.4.2
Keywords: parse, json, parseJSON, whitespace, 160, a0, nbsp Cc: maggrave@nox.pl
Blocked by: Blocking:
Description

It seems that recently added jQuery.parseJSON() have problems with parsing strings which contains multiple non-breaking whitespaces.

See example below, between BEG[ and ]END i've placed set of 0xA0 characters.

<script src='http://code.jquery.com/jquery-1.4.2.js' type="text/javascript"></script> <script> var d = '{"a":"BEG[                              ]END"}'; var jso = jQuery.parseJSON( d ); </script>

Note: make sure that while testing you are testing this is with real 0xA0 characers, copying code from this ticket may replace 0xA0 chars with normal space 0x20 in this case you won't be able to replicate an issue.

It works fine when there is only few of such spaces, when string of whitespaces is longer (let's say 20+) than browsers behave funky (freezes and/or crashes)

OS: Windows Server 2003 R2 SE SP2

Issue found in:

Works fine in:

  • Opera 10.54
  • IE8
  • Safari 4.0.5
Attachments (1)
  • test.rar (0.3 KB) - added by maggrave June 15, 2010 08:47AM UTC.
Change History (11)

Changed June 12, 2010 03:21AM UTC by dmethvin comment:1

resolution: → worksforme
status: newclosed

I tried your example in Firefox 3.6.3 using both A0 characters and \\u00A0 escape sequences in the string and it worked for me.

The actual charset of the file containing the script snippet above could make a big difference. A literal A0 character in the script file would only be valid if the charset of the script was ISO-8859-1. If the file containing this script was UTF-8 then the browser might well see them as invalid characters. I tried adding a meta utf-8 tag but still didn't get any error.

If you can consistently reproduce the problem, reopen the ticket and attach your test case.

Changed June 15, 2010 08:50AM UTC by maggrave comment:2

resolution: worksforme
status: closedreopened

Reopening per suggestion above, please retest with attached file. Just open this html file in

Changed July 11, 2010 11:48PM UTC by dmethvin comment:3

component: unfiledajax

Changed October 14, 2010 09:13PM UTC by ernestohs@gmail.com comment:4

Workaround

This works for me (fix problem on Firefox & Google Chrome):

http://jsfiddle.net/Z5dPY/1/

patch:
501,504c501,502
<         if ($.browser.msie) {
<             // Make sure leading/trailing whitespace is removed (IE can't handle it)
<             data = jQuery.trim(data);
<         }
---
> 		// Make sure leading/trailing whitespace is removed (IE can't handle it)
> 		data = jQuery.trim( data );


Ernesto.

http://www.twitter.com/ernestohs

Changed November 21, 2010 10:34PM UTC by jitter comment:5

_comment0: I tried the test case provied by maggrave and it does freeze FF 3.6.12 with jQuery 1.4.2. Switching to jQuery 1.4.4 fixes the problem and the test case completes with no problems. \ \ If you feel closing this ticket was incorrect or the bug still persists for you, feel free to report back with a reproducible test case and to reopen the ticket. 1290379230272809
milestone: 1.4.21.4.4
priority: → high
resolution: → fixed
status: reopenedclosed

I tried the test case provied by maggrave and it does freeze FF 3.6.12 with jQuery 1.4.2. Switching to jQuery 1.4.4 fixes the problem and the test case completes with no problems and parsing the data correctly.

If you feel closing this ticket was incorrect or the bug still persists for you, feel free to report back with a reproducible test case and to reopen the ticket.

Changed January 20, 2011 10:45PM UTC by Joseph comment:6

I am having the same problem with jquery 1.4.2 and tried with the new version of jquery, and can confirm that it is fixed. However, as I am unable to upgrade the my current version of jquery because it is used with lots of plugins etc.. and it will take long time to do all the updates and tests, I would like to know how can I fix the problem without upgrading my jquery 1.4.2?

Tried many many things, but unable to fix it for Firefox. I fixed it for IE7 but firefox just wont take it and it freezes for around 3-4 mins before it responds again.

Changed January 20, 2011 11:45PM UTC by danheberden comment:7

_comment0: Joseph, just use json2.js - here's how to shove it into parseJSON for ajax callbacks 'n what not... http://jsfiddle.net/danheberden/E444c/ \ \ https://github.com/douglascrockford/JSON-js1295567325430217

Joseph, just use json2.js - here's how to shove it into parseJSON for ajax callbacks 'n what not... http://jsfiddle.net/danheberden/8rUgd/

https://github.com/douglascrockford/JSON-js

Changed January 21, 2011 10:09AM UTC by Joseph comment:8

I tried with JSON2 but still have the same problem. I tried though with latest version of jquery and no problem there.

However, it could be my json has many none-breaking whitespaces.

Tried with native built-in browser and eval, same thing in firefox but IE7 no problem.

Do you have an idea how JQuery parse JSON in the new version?

Changed January 21, 2011 10:14AM UTC by Joseph comment:9

Tried to remove all multiple whitespaces with the following regex and it worked. So it has something to do with whitespaces still in firefox parsing.

myString.replace(/\\s+/g, ' ');

Changed January 21, 2011 10:16AM UTC by Joseph comment:10

Tried to remove all multiple whitespaces with the following regex and it worked. So it has something to do with whitespaces still in firefox parsing.


myString.replace(/\\s+/g, ' ');

Changed January 21, 2011 02:55PM UTC by jitter comment:11

_comment0: Replying to [comment:10 Joseph]: \ > Tried to remove all multiple whitespaces with the following regex and it worked. So it has something to do with whitespaces still in firefox parsing. \ > \ > {{{ \ > \ > myString.replace(/\\s+/g, ' '); \ > }}} \ \ In the future, instead of posting on an old closed/fixed ticket on the bug tracker, please try the [http://webchat.freenode.net/?channels=#jquery #jquery irc channel on freenode] or the [http://forum.jquery.com jQuery Forum] for such support requests. There you will be able to gain help much quicker. \ \ ----- \ \ This was a regex bug in FF check #7477 for more information. \ \ To workaround this in 1.4.2 try including this [http://pastebin.com/SE42Bkk5 snippet] right after you load jQuery.1295621808699123

Replying to [comment:10 Joseph]:

Tried to remove all multiple whitespaces with the following regex and it worked. So it has something to do with whitespaces still in firefox parsing.
> 
> myString.replace(/\\s+/g, ' ');
> 

In the future, instead of posting on an old closed/fixed ticket on the bug tracker, please try the #jquery irc channel on freenode or the jQuery Forum for such support requests. There you will be able to gain help much quicker.


This was a regex bug in FF check #7477 for more information.

To workaround this in 1.4.2 try including this snippet right after you load jQuery.