Fix bugs when dealing with special characters in labels
This commit is contained in:
parent
63e1053afa
commit
3a9e7d3999
@ -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 allLabels = inDocument.getElementsByTagName("label");
|
||||||
|
var regExp = new RegExp('^\\W*' + RegExp.escape(locator) + '(\\b|$)', 'i');
|
||||||
|
|
||||||
var candidateLabels = $A(allLabels).select(function(candidateLabel){
|
var candidateLabels = $A(allLabels).select(function(candidateLabel){
|
||||||
var regExp = new RegExp('^' + locator + '\\b', 'i');
|
|
||||||
var labelText = getText(candidateLabel).strip();
|
var labelText = getText(candidateLabel).strip();
|
||||||
return (labelText.search(regExp) >= 0);
|
return (labelText.search(regExp) >= 0);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user