Closed Bug 196675 Opened 22 years ago Closed 22 years ago

replace is too much sensible to reg exp

Categories

(Core :: JavaScript Engine, defect)

x86
Windows 2000
defect
Not set
normal

Tracking

()

VERIFIED WORKSFORME

People

(Reporter: max, Assigned: rogerl)

Details

(Whiteboard: [js1.2])

Attachments

(2 files)

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.1) Gecko/20020826 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.1) Gecko/20020826 (sorry for my english) in a simple function of replace: str.replace("[wordtosearch]","change"); the function replace take the 1st arg as a RegExp, but it's written in string way, the method to use an ereg is to write like this: ereg = /withoutapexes/properties; or: ereg = new RegExp("withapexes",properties); So this: var = "string"; Can only be a string! But sometimes (i notice this problem in long javascript pages) the 1st argument even if is written like a string is taken as ereg, and it's a very disaster!!!!! I use a lot [ and ] in the ereg they define classes of chars. Here is my code: function AMLtoHTML(str,tag,htmltag,closetag) { while (str.indexOf("["+tag+"]")!=-1) { str = str.replace("["+tag+"]"),htmltag); str = str.replace("[/"+tag+"]")),closetag); } return str; } function AML(str) { str = AMLtoHTML(str,'rosso','<font color="red">','</font>'); str = AMLtoHTML(str,'blu','<font color="blue">','</font>'); return str; } str = AML("[rosso]fantastic this would be red[/rosso]"); If i cut and paste this code on a single page, it works fine!!!!! But in a complex and long page of javascript this function see the 1st arg as ereg exp. The only way to make everything work on mozilla and ie is transform everything in an ereg exp, like this: function AMLtoHTML(str,tag,htmltag,closetag) { while (str.indexOf("["+tag+"]")!=-1) { str = str.replace((new RegExp("\\["+tag+"\\]")),htmltag); str = str.replace((new RegExp("\\[\\/"+tag+"\\]")),closetag); } return str; } function AML(str,q) { str = AMLtoHTML(str,'rosso','<font color="red">','</font>'); str = AMLtoHTML(str,'blu','<font color="blue">','</font>'); return str; } I'm sorry I cannot show you the problem using a link 'cause this is part of a user area of a website and i cannot give id or pass to access to it. Reproducible: Sometimes Steps to Reproduce: 1.use replace(); in a very big document with a lot of javascript! 2.maybe it show you the bug... 3..... or maybe not. Actual Results: if i pass [rosso]rosso[/rosso] as 1st arg it returns: [<f</font>nt color="red">osso]rosso[/rosso] Expected Results: <font color="red">rosso</font> This seems to be another problem related to EregExp Bugzilla Bug 165353 http://bugzilla.mozilla.org/show_bug.cgi?id=165353
> The only way to make everything work on mozilla and ie max: is the same problem occurring in IE, too? If so, it sounds like there might be some mistake in your script, rather than a bug in Mozilla. Both Mozilla and IE agree on the two testcases I attached above. Note bug 165353 is a problem in Mozilla all the time. It happens in large scripts and in small scripts, too. If you feel comfortable with a debugger, you can debug your script in Mozilla via Tools > Web Development > JavaScript Debugger You can search for errors in Tools > Web Development > JavaScript Console One question: what do your script tags look like? Like this: <script language="JavaScript"> <---- current version (1.5) or this: <script language="JavaScript1.2"> <---- version 1.2 Some methods behave differently in earlier versions of the language.
> I'm sorry I cannot show you the problem using a link 'cause this is part > of a user area of a website and i cannot give id or pass to access to it. max: can you make a reduced testcase? That is, an HTML page that has the minimum amount of HTML and JavaScript to demonstrate the bug. You can attach it to this report via the "Create a New Attachment" link above. Then we can look at what's going wrong. Otherwise, we'll have to resolve this bug as "WORKSFORME", because we can't reproduce it -
>max: is the same problem occurring in IE, too? If so, it sounds >like there might be some mistake in your script, rather than a >bug in Mozilla. No the same problem doen't appear under IE, but i have to make scripts works under both browser so i told you: to make it works fine even on mozilla i have to transform in an ereg directly so both browser respond in the same way. >Both Mozilla and IE agree on the two testcases I attached above. in a small script (also when i created this script) on mozilla works fine, but in that long script it works bad! >Tools > Web Development > JavaScript Debugger I don't understand how to use, it continue debuggin this file: venkman-service.js at line 245 >You can search for errors in Tools > Web Development > JavaScript Console Already done! :) no error, i think for mozilla it's right take the 1st arg as ereg. >One question: what do your script tags look like? >Like this: <script language="JavaScript"> <---- current version (1.5) >or this: <script language="JavaScript1.2"> <---- version 1.2 >Some methods behave differently in earlier versions of the language. Really?? I didn't know it!!! <script language="javascript1.1">, maybe can be this, wait, i'll try to change this!
IT WAS THAT!!!! I'm sorry for the waste of time, but i didn't know it could be a reason of this problem.... i delete the version of javascript from the script and it turns to work fine, i added recently the version for a script and i miss that the script doesn't working fine from that moment. I'm sorry! THANK YOU, my sites are again perfect on mozilla! YEAH!
max: thanks, I am resolving this bug as WORKSFORME! Thank you for supporting Mozilla/Netscape. If you are interested, here are some links on the Mozilla JavaScript Debugger: http://www.mozilla.org/projects/venkman/venkman-walkthrough.html http://www.hacksrus.com/~ginda/venkman/faq/venkman-faq.html
Status: UNCONFIRMED → RESOLVED
Closed: 22 years ago
Resolution: --- → WORKSFORME
Marking Verified -
Status: RESOLVED → VERIFIED
Whiteboard: [js1.2]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: