New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
querySelector/All can accidentally return the scoping element #263
Comments
Finally this will be clarified, @annevk some times ago (~2014) I pointed to you via e-mail the same strange behaviour:
Now I see that at that time I make more description: "I see that SELECTORS was changed and DOM was upgrade, but still sth is missing. I have some problem to add topic in mailing list for Selector, so I will try write all to you, especially if I considering only some DOM methods...." << unfortunately this new text never send to you (still don't know why), but here I again touch this "scope-filtered selectors" question. Regardless of this, @tabatkins can you add to SELECTORS4 spec. some real small example showing difference beetwen scope-contained selectors and scope-filtered selectors because the terminology of this specification is difficult at first contact? |
The difference between scope-contained and scope-filtered isn't germane to this issue; both of them consider the scoping element to be in scope. The difference is just whether the entire selector has to match inside the scope (scope-contained) or if only the final selected element has to be inside the scope (scope-filtered). |
So step 3 of https://dom.spec.whatwg.org/#scope-match-a-selectors-string needs to change to store the result in variable and then remove any instances of node from that variable and then return that variable? Why does DOM need to handle this and not SELECTORS? Does SELECTORS have other callers that want this kind of behavior? |
Yes. It's what was (intentionally!) used for It's just this case, with an absolute selector that still wants to act kinda like a relative selector, that's problematic. |
Hmm, so |
Yeah, I guess you're right. Without scoped styles there's no call for scope-contained at all anymore, and you're indeed correct that relative selectors don't actually filter at all (the absolutization process just does something similar automatically). So I guess I can simplify this to just have a single method of scoping, and fix it to automatically exclude the scoping element. You'll need to adjust your links when I rename things; I'll ping you in a bit to let you know what needs to be changed. |
Okay, done. I cut the concepts of "scope-contained" and "scope-filtered", so now there's just "scoped". And scoping doesn't include the scoping element, just its descendants. |
Thanks! |
This accounts for whatwg/dom#263.
This accounts for whatwg/dom#263.
This accounts for whatwg/dom#263.
This accounts for whatwg/dom#263.
This accounts for whatwg/dom#263.
https://dom.spec.whatwg.org/#selectors
Scope-filtered selectors still allow the scoping element to be returned. Thus per spec,
el.querySelector("*")
will returnel
(plus its descendants of course). However, I don't think this is intended, and it doesn't match implementations, who all omit the scoping element from the results.You'll want to manually remove the scoping element from the results if they show up.
(Reporting this for @nox so they don't forget.)
The text was updated successfully, but these errors were encountered: