diff --git a/src/nwmatcher-base.js b/src/nwmatcher-base.js index 4f88a95..3ab93a9 100644 --- a/src/nwmatcher-base.js +++ b/src/nwmatcher-base.js @@ -259,13 +259,13 @@ _byId = !('fileSize' in doc) ? function(id, from) { - id = id.replace(/\\/g, ''); + id = id.replace(/\\([^\\]{1})/g, '$1'); return from.getElementById && from.getElementById(id) || byIdRaw(id, from.getElementsByTagName('*')); } : function(id, from) { var element = null; - id = id.replace(/\\/g, ''); + id = id.replace(/\\([^\\]{1})/g, '$1'); if (XML_DOCUMENT || from.nodeType != 9) { return byIdRaw(id, from.getElementsByTagName('*')); } @@ -367,6 +367,7 @@ name = match[1].toLowerCase(); if (match[2] && match[4] && (type = Operators[match[2]])) { test = name in INSENSITIVE_MAP; + match[4] = match[4].replace(/(\x22|\x27)/g, '\\$1'); match[4] = match[4].replace(/\\([0-9a-f]{2,2})/, '\\x$1'); type = type.replace(/\%m/g, test ? match[4].toLowerCase() : match[4]); expr = 'n=s.getAttr(e,"' + name + '")' + (test ? '.toLowerCase()' : '') + ';'; @@ -381,6 +382,7 @@ } } else if (match[2] == '!=' || match[2] == '=') { expr = 'n=e.attributes["' + name + '"];'; + match[4] = match[4].replace(/(\x22|\x27)/g, '\\$1'); type = 'n&&n.value' + match[2] + '="' + match[4] + '"'; } else { expr = ''; @@ -552,12 +554,9 @@ if ('#' + token == selector) { callback && callback(element); elements = [ element ]; - } - if (/[>+~]/.test(selector)) { + } else if (/[>+~]/.test(selector)) { from = element.parentNode; } else { - selector = selector.replace('#' + token, '*'); - lastPosition -= token.length + 1; from = element; } } else elements = [ ]; diff --git a/src/nwmatcher.js b/src/nwmatcher.js index 05d2033..afbae36 100644 --- a/src/nwmatcher.js +++ b/src/nwmatcher.js @@ -398,9 +398,9 @@ // dynamic attributes that needs to be checked against original HTML value ATTR_DEFAULT = { - value: 'defaultValue', - checked: 'defaultChecked', - selected: 'defaultSelected' + 'value': 'defaultValue', + 'checked': 'defaultChecked', + 'selected': 'defaultSelected' }, // attribute referencing URI data values need special treatment in IE @@ -591,13 +591,13 @@ // @return reference or null _byId = !BUGGY_GEBID ? function(id, from) { - id = id.replace(/\\/g, ''); + id = id.replace(/\\([^\\]{1})/g, '$1'); return from.getElementById && from.getElementById(id) || byIdRaw(id, from.getElementsByTagName('*')); } : function(id, from) { var element = null; - id = id.replace(/\\/g, ''); + id = id.replace(/\\([^\\]{1})/g, '$1'); if (XML_DOCUMENT || from.nodeType != 9) { return byIdRaw(id, from.getElementsByTagName('*')); } @@ -669,7 +669,7 @@ // @return array byName = function(name, from) { - return select('[name="' + name.replace(/\\/g, '') + '"]', from); + return select('[name="' + name.replace(/\\([^\\]{1})/g, '$1') + '"]', from); }, // elements by class (raw) @@ -677,7 +677,7 @@ byClassRaw = function(name, from) { var i = -1, j = i, data = [ ], element, elements = _byTag('*', from), n; - name = ' ' + (QUIRKS_MODE ? name.toLowerCase() : name).replace(/\\/g, '') + ' '; + name = ' ' + (QUIRKS_MODE ? name.toLowerCase() : name).replace(/\\([^\\]{1})/g, '$1') + ' '; while ((element = elements[++i])) { n = XML_DOCUMENT ? element.getAttribute('class') : element.className; if (n && n.length && (' ' + (QUIRKS_MODE ? n.toLowerCase() : n). @@ -693,7 +693,7 @@ _byClass = function(name, from) { return (BUGGY_GEBCN || BUGGY_QUIRKS_GEBCN || XML_DOCUMENT || !from.getElementsByClassName) ? - byClassRaw(name, from) : slice.call(from.getElementsByClassName(name.replace(/\\/g, '')), 0); + byClassRaw(name, from) : slice.call(from.getElementsByClassName(name.replace(/\\([^\\]{1})/g, '$1')), 0); }, // publicly exposed byClass @@ -990,10 +990,12 @@ // case treatment depends on document HTML_TABLE['class'] = QUIRKS_MODE ? 1 : 0; // replace escaped values and HTML entities + match[4] = match[4].replace(/(\x22|\x27)/g, '\\$1'); match[4] = match[4].replace(/\\([0-9a-f]{2,2})/, '\\x$1'); test = (XML_DOCUMENT ? XHTML_TABLE : HTML_TABLE)[expr.toLowerCase()]; type = type.replace(/\%m/g, test ? match[4].toLowerCase() : match[4]); } else if (match[2] == '!=' || match[2] == '=') { + match[4] = match[4].replace(/(\x22|\x27)/g, '\\$1'); type = 'n' + match[2] + '="' + match[4] + '"'; } @@ -1137,7 +1139,7 @@ return ''; } else { if ('compatMode' in doc) { - source = 'if(!' + compile([expr], '', false) + '(e,s,r,d,h,g)){' + source + '}'; + source = 'if(!' + compile(expr, '', false) + '(e,s,r,d,h,g)){' + source + '}'; } else { source = 'if(!s.match(e, "' + expr.replace(/\x22/g, '\\"') + '",g)){' + source +'}'; } @@ -1432,12 +1434,9 @@ if ('#' + token == selector) { callback && callback(element); elements = [ element ]; - } - if (/[>+~]/.test(selector)) { + } else if (/[>+~]/.test(selector)) { from = element.parentNode; } else { - selector = selector.replace('#' + token, '*'); - lastPosition -= token.length + 1; from = element; } } else elements = [ ];