Closed Bug 156465 Opened 23 years ago Closed 23 years ago

Regex incorrectly handles replacement tokens in supplied scenario...

Categories

(Core :: JavaScript Engine, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

VERIFIED DUPLICATE of bug 123437

People

(Reporter: drub0y, Assigned: rogerl)

Details

Attachments

(1 file)

The following code snippet should provide all the information necessary to reproduce the bug. Please note that I've tried other expressions on empty strings without similar results. ------------------------------------- // A regex to trim strings var objTrimmingRegexp = /^s*(S+(s+S+)*)*s*$/g; // right answer IE4+, NS4.x, NS6.x, Mozilla1.0 window.alert(" hello world! ".replace(objTrimmingRegexp , "\"$1"")); //right answer IE4+, NS4.x, NS6.x // wrong answer Mozilla1.0 window.alert(" ".replace(objTrimmingRegexp, "\"$1""));
The testcase has been snarled by '\' stripping. Should be: var objTrimmingRegexp = /^\s*(\S+(\s+\S+)*)*\s*$/g; and then objTrimmingRegexp.exec(" ") should result in [" ", ] but is [" "] instead. Which is a duplicate of Bug 123437. (which is fixed by the patch in Bug 85721 - maybe I should come up with a separate individual patch for this, Phil?) *** This bug has been marked as a duplicate of 123437 ***
Status: UNCONFIRMED → RESOLVED
Closed: 23 years ago
Resolution: --- → DUPLICATE
Attached file HTML testcase
When I try the above testcase in NN4.7 or IE6, this is what I get: // A regexp to trim strings - re = /^\s*(\S+(\s+\S+)*)*\s*$/g str = " hello world! " (note single spaces on each side) str.replace(re, "\"$1\"") = "hello world!" str = " " (i.e. just a single space) str.replace(re, "\"$1\"") = "" Whereas in Mozilla, the latter case fails: str = " " (i.e. just a single space) str.replace(re, "\"$1\"") = "$1" Drew, is that what you saw, too?
Yes sir that's exactly what I ended up with.
OK, thanks! I will then verify this as a duplicate of bug 123437, and add the above testcase to that bug -
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: