Selector: Unescape class name in filter.CLASS#5843
Open
rootvector2 wants to merge 1 commit into
Open
Conversation
2 tasks
gibson042
approved these changes
Jun 15, 2026
Comment on lines
+456
to
+469
| var pattern, | ||
| unescapedClass = unescapeSelector( className ); | ||
|
|
||
| if ( ( pattern = classCache[ unescapedClass + " " ] ) ) { | ||
| return pattern; | ||
| } | ||
| return classCache( unescapedClass, function( elem ) { | ||
| var classAttr = typeof elem.className === "string" && elem.className || | ||
| typeof elem.getAttribute !== "undefined" && | ||
| elem.getAttribute( "class" ) || | ||
| ""; | ||
| return ( " " + classAttr.replace( rwhitespace, " " ) + " " ) | ||
| .indexOf( " " + unescapedClass + " " ) > -1; | ||
| } ); |
Member
There was a problem hiding this comment.
Since we're no longer constructing a RegExp instance, I don't think classCache carries its own weight. Let's drop it.
Suggested change
| var pattern, | |
| unescapedClass = unescapeSelector( className ); | |
| if ( ( pattern = classCache[ unescapedClass + " " ] ) ) { | |
| return pattern; | |
| } | |
| return classCache( unescapedClass, function( elem ) { | |
| var classAttr = typeof elem.className === "string" && elem.className || | |
| typeof elem.getAttribute !== "undefined" && | |
| elem.getAttribute( "class" ) || | |
| ""; | |
| return ( " " + classAttr.replace( rwhitespace, " " ) + " " ) | |
| .indexOf( " " + unescapedClass + " " ) > -1; | |
| } ); | |
| var unescapedClass = " " + unescapeSelector( className ) + " "; | |
| return function( elem ) { | |
| var classes = getClass( elem ); | |
| return ( " " + classes.replace( rwhitespace, " " ) + " " ) | |
| .indexOf( unescapedClass ) > -1; | |
| }; |
Author
There was a problem hiding this comment.
done. dropped classCache and its now-unused declaration, and the matcher returns directly. left the class read inline rather than calling getClass since that lives in attributes/classes.js and importing it here would pull the class-manipulation methods into the selector module. can switch to it if you'd prefer.
mgol
added a commit
to mgol/jquery
that referenced
this pull request
Jun 15, 2026
whatwg/html#12205 made options & optgroups inside a disabled `<select>` match `:disabled` (and not `:enabled`), even without their own `disabled` attribute. This broke the "pseudo - :(dis|en)abled, optgroup and option" test in browsers that implement the change. jQuery's internals are left as-is for now; the test now just accepts both the old & new behavior. A separate companion test was added that forces the jQuery selector engine via `.filter()`; that path keeps the old semantics in every browser. Ref whatwg/html#12205 Ref jquerygh-5843
mgol
added a commit
that referenced
this pull request
Jun 15, 2026
whatwg/html#12205 made options & optgroups inside a disabled `<select>` match `:disabled` (and not `:enabled`), even without their own `disabled` attribute. This broke the "pseudo - :(dis|en)abled, optgroup and option" test in browsers that implement the change. jQuery's internals are left as-is for now; the test now just accepts both the old & new behavior. A separate companion test was added that forces the jQuery selector engine via `.filter()`; that path keeps the old semantics in every browser. Closes gh-5851 Ref whatwg/html#12205 Ref gh-5843
ba5c8da to
6270476
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Noticed
filter.CLASSinterpolates the raw token text into the cachedregex, while
filter.IDandfilter.TAGboth run the captured identifierthrough
unescapeSelectorfirst. So when.foo\41 barreaches theseed-based filter path (e.g.
.filter()on a multi-element set), itcompares against the literal text
foo\41 bar, plus\41becomes aJS-regex octal/backreference. Unescape the captured class first and
switch to indexOf, matching the pattern already used by ATTR
~=.