Skip to content

Commit

Permalink
Fix bugs when dealing with special characters in labels
Browse files Browse the repository at this point in the history
  • Loading branch information
brynary committed Sep 18, 2009
1 parent 63e1053 commit 3a9e7d3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/webrat/selenium/location_strategy_javascript/label.js
@@ -1,7 +1,20 @@
RegExp.escape = function(text) {
if (!arguments.callee.sRE) {
var specials = [
'/', '.', '*', '+', '?', '|',
'(', ')', '[', ']', '{', '}', '\\'
];
arguments.callee.sRE = new RegExp(
'(\\' + specials.join('|\\') + ')', 'g'
);
}
return text.replace(arguments.callee.sRE, '\\$1');
}

var allLabels = inDocument.getElementsByTagName("label");
var regExp = new RegExp('^\\W*' + RegExp.escape(locator) + '(\\b|$)', 'i');

var candidateLabels = $A(allLabels).select(function(candidateLabel){
var regExp = new RegExp('^' + locator + '\\b', 'i');
var labelText = getText(candidateLabel).strip();
return (labelText.search(regExp) >= 0);
});
Expand Down

0 comments on commit 3a9e7d3

Please sign in to comment.