Skip to content

Commit a9ca629

Browse files
chrislukeis
authored andcommitted
fix xpath translate() function for RegEx special characters
Fixes Issue #4585 Signed-off-by: Luke Inman-Semerau <luke.semerau@gmail.com>
1 parent 977c310 commit a9ca629

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

javascript/selenium-core/xpath/xpath.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,10 @@ FunctionCallExpr.prototype.xpathfunctions = {
12361236
var s2 = this.args[2].evaluate(ctx).stringValue();
12371237

12381238
for (var i = 0; i < s1.length; ++i) {
1239-
s0 = s0.replace(new RegExp(s1.charAt(i), 'g'), s2.charAt(i));
1239+
var c = s1.charAt(i);
1240+
if ("^.|?+*(){}[]\\$".indexOf(c) != -1)
1241+
c = "\\" + c; // escape special characters
1242+
s0 = s0.replace(new RegExp(c, 'g'), s2.charAt(i));
12401243
}
12411244
return new StringValue(s0);
12421245
},

0 commit comments

Comments
 (0)