-
Notifications
You must be signed in to change notification settings - Fork 39
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
:scope not working when the context has a class name that uses special characters #106
Comments
I think I have found where the error is thrown: https://github.com/dperini/nwsapi/blob/master/src/nwsapi.js#L896-L1277 I think it's because |
After looking more into it, I have found one possible solution, although maybe it's not the way you want to approach this. I have added in the // replace ':scope' pseudo-class with element references
makeref =
function(selectors, element) {
// DOCUMENT_NODE (9)
if (element.nodeType === 9) {
element = element.documentElement;
}
return selectors.replace(/:scope/ig,
element.localName +
(element.id ? '#' + element.id : '') +
(element.className ? '.' + escape(element.classList[0]) : ''));
},
// This is not the correct way to escape special characters in an identifier, it's just a proof of concept
escape = function(string) {
return string.replace(/[!"#$%&'()*+,./;<=>?@\[\\\]^`{|}~\t\n\v\f:]/, match => '\\' + match);
}, Because when using I think nwsapi should escape the class name when replacing |
@jordimarimon This fix will be in next revision. I will commit as soon as I am back to my desk. |
Minimal example that breaks in the latest nwsapi (I have downloaded the
nwsapi.js
file from github today):This throws
Uncaught DOMException: unknown pseudo-class selector ':p-4>[data-test="foo"]'
but if I try the query selector API provided by the browser it works.I'm using tailwind which makes use of special characters in the class names and I was running tests with jest using jsdom as the environment and it's when I encounter the error.
Is this use case something that nwsapi would be open to support?
I will try to help by finding out how this could be fixed and in case that I do find it, I could open a PR if it's okay?
The text was updated successfully, but these errors were encountered: