Skip to content

Commit

Permalink
synchronized 'noqsa' and 'base' versions with the 'escpaed CSS identi…
Browse files Browse the repository at this point in the history
…fier' change also for class names, added test cases in test/css3-escape
  • Loading branch information
dperini committed Oct 17, 2016
1 parent 6d551c3 commit 591ed24
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/nwmatcher-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) ? '' : '*');
}
Expand Down
2 changes: 1 addition & 1 deletion src/nwmatcher-noqsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) ? '' : '*');
}
Expand Down
9 changes: 9 additions & 0 deletions test/css3-escape/test_nwmatcher_escaped_identifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 591ed24

Please sign in to comment.