#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: | [email protected]… |
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)
Change History (12)
comment:1 Changed 13 years ago by
Resolution: | → worksforme |
---|---|
Status: | new → closed |
Changed 13 years ago by
comment:2 Changed 13 years ago by
Resolution: | worksforme |
---|---|
Status: | closed → reopened |
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 13 years ago by
Component: | unfiled → ajax |
---|
comment:4 Changed 12 years ago by
Workaround
This works for me (fix problem on Firefox & Google Chrome):
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.
comment:5 Changed 12 years ago by
Milestone: | 1.4.2 → 1.4.4 |
---|---|
Priority: | → high |
Resolution: | → fixed |
Status: | reopened → closed |
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.
comment:6 Changed 12 years ago by
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 12 years ago by
Joseph, just use json2.js - here's how to shove it into parseJSON for ajax callbacks 'n what not... http://jsfiddle.net/danheberden/8rUgd/
comment:8 Changed 12 years ago by
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 12 years ago by
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 follow-up: 11 Changed 12 years ago by
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 Changed 12 years ago by
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.
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.