Closed Bug 318303 Opened 19 years ago Closed 19 years ago

javascript replace in string doesn't work when replacing a bracket

Categories

(Core :: JavaScript Engine, defect)

1.7 Branch
x86
Windows XP
defect
Not set
minor

Tracking

()

RESOLVED INVALID

People

(Reporter: noel, Unassigned)

Details

Attachments

(2 files)

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6 when using the replace tag of javascript everything works fine except when replacing a bracket ([). the java console shows: unterminated character class it should not be in the java engine cause i checked more browsers but only firefox won't replace. Reproducible: Always Steps to Reproduce: 1. <html><body><script language="javascript1.2"> var thisstring='someteststring[withbracket' alert(thisstring.replace('[','')) </script></body></html> 2. <html><body><script language="javascript1.2"> var thisstring='someteststring[withbracket' alert(thisstring.replace('\[','')) </script></body></html> 3. Actual Results: Javascript Console: Error: unterminated character class Expected Results: alert window "someteststringwithbracket"
shows a function wich replaced the bracket (error in firefox) shows a function wich replaced the escaped bracket (error in firefox) shows a function wich splits the string at the bracket and adds all together again (quick fix)
Have you tested this in Firefox 1.5? Works fine for me.
Ah, that would be because bug 309840 fixed this for 1.5. *** This bug has been marked as a duplicate of 309840 ***
Status: UNCONFIRMED → RESOLVED
Closed: 19 years ago
Resolution: --- → DUPLICATE
This is not a dupe of bug 309840. In JavaScript 1.4 or prior, 1st argument for String#replace() is always treated as a regular expression even if it is a plain string (unlike ECMA/JS1.5+ which treats plain strings "as is"). So, |thisstring.replace('[','')| should throw an error in JS1.2. However, Firefox 1.5 ignores version specified in |language| attribute of HTML |script| elements (see bug 255895), and you didn't see the error.
Ah, ok, I hadn't noticed the "javascript1.2". I suppose this is INVALID, then?
Status: RESOLVED → UNCONFIRMED
Resolution: DUPLICATE → ---
yeah, invalid.
Assignee: nobody → general
Component: General → JavaScript Engine
Product: Firefox → Core
QA Contact: general → general
Version: unspecified → 1.7 Branch
Status: UNCONFIRMED → RESOLVED
Closed: 19 years ago19 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: