Bug Tracker

Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#6577 closed bug (fixed)

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@…
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:

  • FireFox 3.6.3
  • Chrome 4.1.249.1064


Works fine in:

  • Opera 10.54
  • IE8
  • Safari 4.0.5

Attachments (1)

test.rar (256 bytes) - added by maggrave 9 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 Changed 9 years ago by dmethvin

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 9 years ago by maggrave

Attachment: test.rar added

comment:2 Changed 9 years ago by maggrave

Resolution: worksforme
Status: closedreopened

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

  • FireFox 3.6.3
  • Chrome 4-5

comment:3 Changed 9 years ago by dmethvin

Component: unfiledajax

comment:4 Changed 9 years ago by ernestohs@…

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

comment:5 Changed 9 years ago by jitter

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.

Last edited 9 years ago by jitter (previous) (diff)

comment:6 Changed 9 years ago by Joseph

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.

comment:7 Changed 9 years ago by danheberden

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

Last edited 9 years ago by danheberden (previous) (diff)

comment:8 Changed 9 years ago by Joseph

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?

comment:9 Changed 9 years ago by 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, ' ');

comment:10 Changed 9 years ago by 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, ' ');

comment:11 in reply to:  10 Changed 9 years ago by jitter

Replying to 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.

Last edited 9 years ago by jitter (previous) (diff)
Note: See TracTickets for help on using tickets.