diff --git a/src/nwmatcher-base.js b/src/nwmatcher-base.js index 22201fb..8b66e62 100644 --- a/src/nwmatcher-base.js +++ b/src/nwmatcher-base.js @@ -695,7 +695,7 @@ } else if (!XML_DOCUMENT && GEBCN && (parts = lastSlice.match(Optimize.CLASS)) && (token = parts[1])) { - if ((elements = from.getElementsByClassName(token.replace(/\\([^\\]{1})/g, '$1'))).length === 0) { return [ ]; } + if ((elements = from.getElementsByClassName(unescapeIdentifier(token))).length === 0) { return [ ]; } selector = selector.slice(0, lastPosition) + selector.slice(lastPosition).replace('.' + token, reOptimizeSelector.test(selector.charAt(selector.indexOf(token) - 1)) ? '' : '*'); } diff --git a/src/nwmatcher-noqsa.js b/src/nwmatcher-noqsa.js index 12b98d3..32bcd04 100644 --- a/src/nwmatcher-noqsa.js +++ b/src/nwmatcher-noqsa.js @@ -864,7 +864,7 @@ } else if (!XML_DOCUMENT && GEBCN && (parts = lastSlice.match(Optimize.CLASS)) && (token = parts[1])) { - if ((elements = from.getElementsByClassName(token.replace(/\\([^\\]{1})/g, '$1'))).length === 0) { return [ ]; } + if ((elements = from.getElementsByClassName(unescapeIdentifier(token))).length === 0) { return [ ]; } selector = selector.slice(0, lastPosition) + selector.slice(lastPosition).replace('.' + token, reOptimizeSelector.test(selector.charAt(selector.indexOf(token) - 1)) ? '' : '*'); } diff --git a/test/css3-escape/test_nwmatcher_escaped_identifiers.js b/test/css3-escape/test_nwmatcher_escaped_identifiers.js index 228538c..8f092e2 100644 --- a/test/css3-escape/test_nwmatcher_escaped_identifiers.js +++ b/test/css3-escape/test_nwmatcher_escaped_identifiers.js @@ -10,20 +10,29 @@ function testMatched(id, selector) { var elems = document.createElement("div"); var a = document.createElement("span"); a.id = id; + a.className = id; elems.appendChild(a); console.assert( NW.Dom.first(selector, elems) === a, `${JSON.stringify(id)} should match with ${JSON.stringify(selector)}`); + console.assert( + NW.Dom.first('.' + selector.slice(1), elems) === a, + `${JSON.stringify(id)} should match with ${JSON.stringify('.' + selector.slice(1))}`); } function testNeverMatched(id, selector) { var elems = document.createElement("div"); var a = document.createElement("span"); a.id = id; + a.className = id; elems.appendChild(a); console.assert( NW.Dom.first(selector, elems) === null, `${JSON.stringify(id)} should never match with ${ JSON.stringify(selector)}`); + console.assert( + NW.Dom.first('.' + selector.slice(1), elems) === null, + `${JSON.stringify(id)} should never match with ${ + JSON.stringify('.' + selector.slice(1))}`); } // 4.3.7 from https://www.w3.org/TR/css-syntax-3/#consume-an-escaped-code-point