PDA

View Full Version : Regular Expression Problem in ajaxtabs script?



gandalf97
05-15-2007, 05:27 PM
1) Script Title: Ajax Tabs Content Script

2) Script URL (on DD): httphttp://www.dynamicdrive.com/dynamicindex17/ajaxtabscontent/index.htm

3) Describe problem: I am running visual studio .net and when I open the script the following line:

var modifiedurl=ulistlink.getAttribute("href").replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+"/")
---^
looks like it doesn't properly escape things because the rest of the line looks like a comment after the two //'s. Is this just a flaw in the dev environment or should the regular expression be enclosed in quotes? Would it hurt to enclose it in quotes?

Thanks!
Gandalf

mwinter
05-15-2007, 06:03 PM
var modifiedurl=ulistlink.getAttribute("href").replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+"/")
---^
looks like it doesn't properly escape things because the rest of the line looks like a comment after the two //'s. Is this just a flaw in the dev environment or should the regular expression be enclosed in quotes?

The editor is flawed, failing to recognise a regular expression literal.



Would it hurt to enclose it in quotes?

Yes, you'd break the script. It could be rewritten to use string literals, but that seems an absurd measure to take. Complain to Microsoft: VS.NET was written after Internet Explorer supported regular expression literals so there's no excuse for not recognising them in a script context.

gandalf97
05-15-2007, 07:22 PM
Mike,

Thanks for the reply. I suspected what you said but wanted to check to be sure. Nice to know I am still somewhat sane.

Regards,
Gandalf