try it. type ')' and there is a javascript error.
apparently, it is not escaped properly yet.
Discussion
-
2006-04-21
Logged In: YES
user_id=850577
Actually this will occur for any character which is a
regular expression operator (eg. \,.*()+$&{}[]^:). I
whipped up a quick regular expression escape function to fix
this.
There's probably a better way, but this works for me:
function regExpEscape(str) {
var result = "";
if(str != null && str.length > 0) {
var i,chr;
for (i = 0; i < str.length; i++) {
chr = str.charAt(i);
if (chr == '.'){result+="\\.";}
else if (chr == '\\'){result+="\\\\";}
else if (chr == '?'){result+="\\?";}
else if (chr == '*'){result+="\\*";}
else if (chr == '+'){result+="\\+";}
else if (chr == '&'){result+="\\&";}
else if (chr == ':'){result+="\\:";}
else if (chr == '{'){result+="\\{";}
else if (chr == '}'){result+="\\}";}
else if (chr == '['){result+="\\[";}
else if (chr == ']'){result+="\\]";}
else if (chr == '('){result+="\\(";}
else if (chr == ')'){result+="\\)";}
else if (chr == '^'){result+="\\^";}
else if (chr == '$'){result+="\\$";}
else{result+=chr;}
}
}
return result;
}//regExpEscape()
Then...
var escapedUserInput = regExpEscape(userInput);
re1m = new RegExp("^([ \"\>\<\-]*)("+escapedUserInput+")","i");
re2m = new RegExp("([ \"\>\<\-]+)("+escapedUserInput+")","i");
re1 = new RegExp("^([ \"\}\{\-]*)("+escapedUserInput+")","gi");
re2 = new RegExp("([ \"\}\{\-]+)("+escapedUserInput+")","gi");
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Logged In: YES
user_id=850577
Actually this will occur for any character which is a
regular expression operator (eg. \,.*()+$&{}[]^:). I
whipped up a quick regular expression escape function to fix
this.
There's probably a better way, but this works for me:
function regExpEscape(str) {
var result = "";
if(str != null && str.length > 0) {
var i,chr;
for (i = 0; i < str.length; i++) {
chr = str.charAt(i);
if (chr == '.'){result+="\\.";}
else if (chr == '\\'){result+="\\\\";}
else if (chr == '?'){result+="\\?";}
else if (chr == '*'){result+="\\*";}
else if (chr == '+'){result+="\\+";}
else if (chr == '&'){result+="\\&";}
else if (chr == ':'){result+="\\:";}
else if (chr == '{'){result+="\\{";}
else if (chr == '}'){result+="\\}";}
else if (chr == '['){result+="\\[";}
else if (chr == ']'){result+="\\]";}
else if (chr == '('){result+="\\(";}
else if (chr == ')'){result+="\\)";}
else if (chr == '^'){result+="\\^";}
else if (chr == '$'){result+="\\$";}
else{result+=chr;}
}
}
return result;
}//regExpEscape()
Then...
var escapedUserInput = regExpEscape(userInput);
re1m = new RegExp("^([ \"\>\<\-]*)("+escapedUserInput+")","i");
re2m = new RegExp("([ \"\>\<\-]+)("+escapedUserInput+")","i");
re1 = new RegExp("^([ \"\}\{\-]*)("+escapedUserInput+")","gi");
re2 = new RegExp("([ \"\}\{\-]+)("+escapedUserInput+")","gi");