From 05184cc448f4ed7715ddd6a5d724e167882415f1 Mon Sep 17 00:00:00 2001 From: Michał Gołębiowski-Owczarek Date: Mon, 18 Nov 2019 22:10:55 +0100 Subject: Selector: Make empty attribute selectors work in IE again qSA in IE 11/Edge often (but not always) don't find elements with an empty name attribute selector (`[name=""]`). Detect that & fall back to Sizzle traversal. Interestingly, IE 10 & older don't seem to have the issue. Fixes gh-4435 Closes gh-4510 --- src/selector.js | 4 +--- src/selector/rbuggyQSA.js | 16 +++++++++++++++- src/selector/var/whitespace.js | 2 ++ 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 src/selector/var/whitespace.js (limited to 'src') diff --git a/src/selector.js b/src/selector.js index 019f25d62..66abe7935 100644 --- a/src/selector.js +++ b/src/selector.js @@ -5,6 +5,7 @@ import documentElement from "./var/documentElement.js"; import indexOf from "./var/indexOf.js"; import pop from "./var/pop.js"; import push from "./var/push.js"; +import whitespace from "./selector/var/whitespace.js"; import rbuggyQSA from "./selector/rbuggyQSA.js"; import support from "./selector/support.js"; @@ -41,9 +42,6 @@ var i, // Regular expressions - // https://www.w3.org/TR/css3-selectors/#whitespace - whitespace = "[\\x20\\t\\r\\n\\f]", - // https://www.w3.org/TR/css-syntax-3/#ident-token-diagram identifier = "(?:\\\\[\\da-fA-F]{1,6}" + whitespace + "?|\\\\[^\\r\\n\\f]|[\\w-]|[^\0-\\x7f])+", diff --git a/src/selector/rbuggyQSA.js b/src/selector/rbuggyQSA.js index f638fc429..2c853a0f1 100644 --- a/src/selector/rbuggyQSA.js +++ b/src/selector/rbuggyQSA.js @@ -1,8 +1,10 @@ import document from "../var/document.js"; import isIE from "../var/isIE.js"; +import whitespace from "./var/whitespace.js"; var rbuggyQSA = [], - testEl = document.createElement( "div" ); + testEl = document.createElement( "div" ), + input = document.createElement( "input" ); testEl.innerHTML = ""; @@ -19,6 +21,18 @@ if ( isIE ) { rbuggyQSA.push( ":enabled", ":disabled" ); } +// Support: IE 11+, Edge 15 - 18+ +// IE 11/Edge don't find elements on a `[name='']` query in some cases. +// Adding a temporary attribute to the document before the selection works +// around the issue. +// Interestingly, IE 10 & older don't seem to have the issue. +input.setAttribute( "name", "" ); +testEl.appendChild( input ); +if ( !testEl.querySelectorAll( "[name='']" ).length ) { + rbuggyQSA.push( "\\[" + whitespace + "*name" + whitespace + "*=" + + whitespace + "*(?:''|\"\")" ); +} + rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join( "|" ) ); export default rbuggyQSA; diff --git a/src/selector/var/whitespace.js b/src/selector/var/whitespace.js new file mode 100644 index 000000000..dcac814c7 --- /dev/null +++ b/src/selector/var/whitespace.js @@ -0,0 +1,2 @@ +// https://www.w3.org/TR/css3-selectors/#whitespace +export default "[\\x20\\t\\r\\n\\f]"; -- cgit v1.2.3