Closed Bug 1076728 Opened 10 years ago Closed 10 years ago

Changed Javascript .replace behavior

Categories

(Core :: JavaScript Engine, defect)

32 Branch
x86_64
Windows 7
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 1033946

People

(Reporter: ristorakete, Unassigned)

References

()

Details

(Keywords: regression)

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

Steps to reproduce:

This piece of Javascript used to work fine in FF 31 and prior. But for 32 it changed to some unpredicted output. It's purpose is to encode non-letter characters in a string to HTML entities. 

function encodeString(str) {
    return str.replace(/[\u00A0-\u9999<>\&]/gim, function(i) {
        return '&#'+i.charCodeAt(0)+';';
    });
}

In FF 31-, Chrome and even IE the desired output is achieved, but FF32 decided to encode the letter 'i' to it's HTML entity representation.

jsFiddle demonstrating the issue: http://jsfiddle.net/Ls2vnjqL/


Actual results:

Output: &#73; am an &#105;nterfer&#105;ng &#105;nc&#105;dent.


Expected results:

Output: I am an interfering incident.
The error applies for the letters: I,S,i,k
Reg range:
good=2014-05-16
bad=2014-05-17
http://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=58c5a3427997&tochange=2893f60d5903

Suspected bug: maybe Bug 1008590.
Component: Untriaged → JavaScript Engine
Keywords: regression
Product: Firefox → Core
It seem to be fixed in Firefox33beta.
(In reply to Loic from comment #2)
> Suspected bug: maybe Bug 1008590.

Bug 976446 is a lot more likely, it added the irregexp engine.

I think this is a duplicate of bug 1033946. Unfortunately the fix for that is in 34 and we didn't backport it. It probably appears fixed in 33 because we're using a Latin1 string in this case and the bug only affects TwoByte strings.

I'll investigate.
Here's a testcase that fails with Firefox 33 (I added \u1200 to the input string to force a TwoByte representation):

http://jsfiddle.net/ocz2mg1w/

Christoph, thanks a lot for the bug report and the great testcase! This is a duplicate of bug 1033946 and will be fixed in Firefox 34. I'll see if we can get that backported to 33 beta but it's probably too late in the release cycle.
Status: UNCONFIRMED → RESOLVED
Closed: 10 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.