Skip to content

Commit

Permalink
Fix querySelector/querySelectorAll patch to convert input into a stri…
Browse files Browse the repository at this point in the history
…ng as browsers do
  • Loading branch information
lahmatiy committed Jun 21, 2018
1 parent 237b406 commit 93925df
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build/dom4.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions build/dom4.max.js
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ THE SOFTWARE.
node.setAttribute(dataScope, null);
var result = method.call(
node,
css.replace(
String(css).replace(
/(^|,\s*)(:scope([ >]|$))/g,
function ($0, $1, $2, $3) {
return $1 + '[' + dataScope + ']' + ($3 || ' ');
Expand All @@ -755,7 +755,8 @@ THE SOFTWARE.
}
}());
}
}(window));(function (global){'use strict';
}(window));
(function (global){'use strict';

// a WeakMap fallback for DOM nodes only used as key
var DOMMap = global.WeakMap || (function () {
Expand Down
4 changes: 2 additions & 2 deletions src/dom4.js
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@
node.setAttribute(dataScope, null);
var result = method.call(
node,
css.replace(
String(css).replace(
/(^|,\s*)(:scope([ >]|$))/g,
function ($0, $1, $2, $3) {
return $1 + '[' + dataScope + ']' + ($3 || ' ');
Expand All @@ -733,4 +733,4 @@
}
}());
}
}(window));
}(window));
12 changes: 11 additions & 1 deletion test/dom4.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,16 @@ wru.test([
findInResult(result, div.childNodes[2]) &&
findInResult(result, div.childNodes[3].childNodes[0])
);

// should take any value as a string
result = div.querySelectorAll([':scope > p', ':scope li', 'h1', 'div > b']);
wru.assert('correct length', result.length === 4);
wru.assert('correct results',
findInResult(result, div.childNodes[0]) &&
findInResult(result, div.childNodes[1]) &&
findInResult(result, div.childNodes[2]) &&
findInResult(result, div.childNodes[3].childNodes[0])
);
}
}
]);
]);

0 comments on commit 93925df

Please sign in to comment.