-
Notifications
You must be signed in to change notification settings - Fork 642
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
[css-selectors][css-escape] Cannot select attributes with multiple escaped chars #4820
Comments
Yes, you are missing something, you should escape the backslash in var li = document.createElement("li");
li.dataset.path = String.raw`c:\WINDOWS\system32\mspaint.exe`;
li.matches(String.raw`li[data-path^="c:\\WINDOWS\\system32\\mspaint.exe"]`); // true
li.matches(String.raw`li[data-path^=c\:\\WINDOWS\\system32\\mspaint\.exe]`); // true |
The missing backslash was a fault of retyping into the box and has been edited. It seems that the thing I'm ACTUALLY missing which you seem to have ACCIDENTALLY gotten right in your attempt to point out a typo rather than give an actual explanation is the use of |
Sure, if you are using JS, you have to escape a backslash twice (once for JS and once for CSS). Or use |
Snark is neither appreciated nor useful.
Yeah, note that you need to escape the backslash both at the JS and the CSS level if you're putting this in querySelector(), because it gets parsed by both languages. Without Inside of a stylesheet you only need to escape it once, since only CSS will be parsing it, so |
The snark was in response to what was essentially a one-line answer only pointing out a typo instead of focusing on the actual fix. I see those kind of no-substance one-liners on Stack Overflow and Quora too often and I'm not a fan of those either. |
|
Given that the use case of a backslash in an attribute is indeed not common, the documentation (at least on MDN at the time) was lacking in that respect and would benefit from an update saying that double-escaping (or While I regret how I presented my text, I am glad I asked the question here and I do thank y'all for providing not just the answer to it specifically but the CSSWG in general for promoting the continuous useful progression of CSS. |
Hello! As someone who isn't part of the WG I wasn't sure where to report the issue so this looked like a reasonable place to do so.
I recently had occasion to want to select an HTML element with an attribute that has a Windows-formatted file path as its main content (i.e. backslash directory separators and a colon separating drive letter and the rest of the path). I asked on Stack Overflow if it was possible, as I was using JavaScript to
querySelector
it and all my attempts to escape the backslashes and colon, either usingCSS.escape
or manually, have failed beyond the first escaped char. Microsoft Visual Studio Code, when on Windows, is what formats paths Windows-style, while on macOS and *nix paths separate with / and targeting seems okay. Sample element and failed selector (actual HTML from VSCode in the Stack Overflow):Is there something I'm missing regarding how to escape the attribute, or is it a fruitless endeavor to try to target an attribute that has a Windows-style path in it?
The text was updated successfully, but these errors were encountered: