Closed Bug 1006744 Opened 10 years ago Closed 10 years ago

JQuery 1.4.2 trim function not working with Firefox 29.0 on long strings

Categories

(Core :: JavaScript Engine, defect)

29 Branch
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 998785

People

(Reporter: jerome.fiolleau, Unassigned)

References

Details

(Keywords: regression)

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36

Steps to reproduce:

With an ajax call, I want to refresh a page fragment, and to minimize the length of the string returned by my response, I use the "trim" function (from JQuery, v1.4.2). Here is the code I use :
$.ajax( {
   url: action+'.do?methode=ajouterLigne&ajax=true&indErreur=0&indNouveau=0',
   data : $("#formulaireDetail").serialize(),
   type: 'POST',
   success: function(data) {
      $('#'+action+'Detail').replaceWith($.trim(data));
   }
});


Actual results:

Here is the result from the console tab in firebug :
an error occurred while executing regular expression
return (text || "").replace( rtrim, "" );

It seems to happen only when the data exceed 70000 characters. If I got less than 70000 (I didn't test exactly with 69999 characters and 70000, but it didn't work with 71320, and it worked with 68954).
It worked great with Firefox 28.0 and previous releases.


Expected results:

The result expected is just the data to be trimmed.
This sounds like a regression from bug 953013.  Before that fix, the regexp would incorrectly not match when it should, instead of throwing...  So it only worked "great" if you didn't have stuff you needed to trim.  ;)

Looking at jQuery 1.4.2, the rtrim regexp looks like this:

	rtrim = /^(\s|\u00A0)+|(\s|\u00A0)+$/g,

which has exactly the sort of problem that would trigger bug 953013.

For comparison, jQuery 1.10.2 has:

	rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,

(note lack of capture groups, which I suspect means it won't have this issue).  

If you're in a position where you can update jQuery it might be worth it...

Till, do you think we can do something to optimize out the capture group bits here when the replacement string is "" (as it is in this case)?
Blocks: 953013
Status: UNCONFIRMED → NEW
Component: General → JavaScript Engine
Ever confirmed: true
Flags: needinfo?(till)
Summary: JQuery trim function not working with Firefox 29.0 → JQuery 1.4.2 trim function not working with Firefox 29.0
Summary: JQuery 1.4.2 trim function not working with Firefox 29.0 → JQuery 1.4.2 trim function not working with Firefox 29.0 on long strings
(In reply to Boris Zbarsky [:bz] from comment #1)
> Till, do you think we can do something to optimize out the capture group
> bits here when the replacement string is "" (as it is in this case)?

The only thing that comes to mind is recompiling the regexp if we know that the capture groups aren't used. In that case, we can treat them as non-capturing. We don't know that at the point where we set up the RegExpObject at the moment, unfortunately.

Given that we're in the process of getting rid of Yarr entirely, and that it looks like that'll happen in time for Firefox 32, I'm inclined to leave this as-is for now. Any patch for Yarr would probably be fairly involved and thus risky to uplift in any case.
Flags: needinfo?(till)
Depends on: 976446
OS: Windows 7 → All
Hardware: x86_64 → All
Thank you for your quick answer !
I swith of JQuery version, ans it's working great.
Keywords: regression
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.