-
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
Infinite loop fixed but still getting error in selectors #83
Comments
See: #82 workaround: "overrides": {
"nwsapi": "2.2.2"
} |
@rocioimpa Furthermore I received confirmation from other devs telling the fix resolved the issue. |
Hello,
To reproduce: it("should not throw", () => {
expect(() =>
document.querySelectorAll("[tabindex]:not(slot):not([inert])")
).not.toThrow();
}); |
Same here with Code: const nodes = document.querySelectorAll('.foo:not(.bar):not([data-id="1"]'); Result: SyntaxError: '.foo):not(.bar):not([data-id="1"]' is not a valid selector
at emit (node_modules\nwsapi\src\nwsapi.js:557:17)
at Object._matches [as match] (node_modules\nwsapi\src\nwsapi.js:1400:9)
at Array.Resolver (eval at compile (node_modules\nwsapi\src\nwsapi.js:760:17), <anonymous>:3:105)
at collect (node_modules\nwsapi\src\nwsapi.js:1552:21)
at Object._querySelectorAll [as select] (node_modules\nwsapi\src\nwsapi.js:1509:36) |
@asamuzaK & @cole-adams
are parsed correctly in version 2.2.4 of "nwsapi", not throwing errors in the console. NW.Dom.Version Also, other developers have confirmed that these bugs were fixed, both the infinite recursion and the multiple ":not()". |
Failed log: Update libs asamuzaK/sidebarTabs@99768e5 I'm not using nwsapi directly, I'm using jsdom which depends on nwsapi. In package.json, temporary added "overrides": {
"jsdom": {
".": "$jsdom",
"nwsapi": "2.2.2"
}
}, Running tests again, it passed. So it looks like v2.2.4 still has a bug. |
Additional test for dperini/nwsapi#83
Updated nwsapi to v2.2.4, it failed. "overrides": {
"jsdom": {
".": "$jsdom",
"nwsapi": "2.2.4"
}
}, |
It looks like the regexp in logicalsel is not correct. Refer to https://github.com/dperini/nwsapi/blob/master/src/nwsapi.js#L1002 console.log(':not(.foo):not(.bar):not([data-baz="1"])'.match(Patterns.logicalsel));
/*
[
':not(.foo):not(.bar):not([data-baz="1"])',
'not',
'.foo):not(.bar):not([data-baz="1"]',
'',
index: 0,
input: ':not(.foo):not(.bar):not([data-baz="1"])',
groups: undefined
]
*/ console.log(':not(.foo):not(.bar, [data-baz="1"])'.match(Patterns.logicalsel));
/*
[
':not(.foo):not(.bar, [data-baz="1"])',
'not',
'.foo):not(.bar, [data-baz="1"]',
'',
index: 0,
input: ':not(.foo):not(.bar, [data-baz="1"])',
groups: undefined
]
*/ console.log(':not(.foo):not(.bar[data-baz="1"])'.match(Patterns.logicalsel));
/*
[
':not(.foo):not(.bar[data-baz="1"])',
'not',
'.foo):not(.bar[data-baz="1"]',
'',
index: 0,
input: ':not(.foo):not(.bar[data-baz="1"])',
groups: undefined
]
*/ If there is an attribute selector at the end of the last |
Hi @rocioimpa, I was facing a similar issue. The error seems to occur when there's an attribute selector (like As of now and using v2.2.4, I've found a couple of workarounds that could help:
:not([tabIndex="-1"]):not(style):not(script):not(noscript):not(link)
:not([tabIndex="-1"], style, script, noscript, link) :not(style, script, noscript, link, [tabIndex="-1"]) |
Hi @cole-adams, you could work around this issue by changing the order of the document.querySelectorAll("[tabindex]:not([inert]):not(slot)") Or you could group the selectors inside a single document.querySelectorAll("[tabindex]:not([inert], slot)") document.querySelectorAll("[tabindex]:not(slot, [inert])") I'm not very familiar with the internals of this library, so the above suggestions are just meant to work around the issue as a consumer of the library. I hope someone with more context of this codebase can find a definite fix, as this issue was not present on v2.2.2. |
|
This suggestion involves using We could change the order of the selectors as suggested here in https://github.com/focus-trap/tabbable/blob/master/src/index.js#L12
but since the order should not matter, it seems like not the right thing to do (or at least not something that should be necessary to do). I think nswapi should fix the bug instead of tabbable (and who knows how many other libraries) changing the order of their selectors just to make it work, aside from trying to mitigate this issue until it's fixed. I might see if I can apply that v2.2.2 override to tabbable's package.json instead and then wait for the fix here. |
|
@stefcameron |
@dperini Thank you for working to fix the issue! Hopefully my fix takes a bit of pressure off for now. 😄 |
I want to share the regular expresssion that I am currently refining to solve the first part of the problem. https://regex101.com/r/QZFy85/1 by adding a ^ (caret sign) at the start of the RE (hooking the RE to the start of the input selector), I am able to pop out the first or the last :not() selector from the string at the correct place. Please, if anybody see a missing or failing case or can spot any inconsistency with this strategy report or suggest. Thank you ! |
@ALL |
@dperini I don't see a PR open with a fix against this issue. What line of code in |
@stefcameron |
@dperini Better late than never! 😉 Thank you for the commit and the updated code. I'll try to give this a try locally later this week when I have time for focus-trap and will report back here with my findings. |
@dperini I installed nwsapi v2.2.5, replaced that one line with your updated one, and ran our tabbable tests. All passed! Though I'll be honest, they also passed with v2.2.5 and the old Regex as-is -- while they did not when this issue first surfaced. I don't understand why. But all passed with your changes. |
https://regex101.com/r/QZFy85/1 |
@asamuzaK
return the same results using "nwsapi" or "native" methods. |
The previous comment is the result of testing with https://regex101.com/r/QZFy85/1
Expected: Actual: |
@asamuzaK Have a look at the included RE.txt document which I quickly created trying to explain this process: |
Hi, the infinite loop issue has been fixed but still getting this test failure in tests that were passing prior to release 2.2.3:
SyntaxError: 'style):not(script):not(noscript):not(link):not([tabIndex="-1"]' is not a valid selector
at emit (node_modules/nwsapi/src/nwsapi/js:557:17)
at Object._matches [as match] (node_modules/nwsapi/src/nwsapi/js:1400:9)
at Array.Resolver (eval at compile (node_modules/nwsapi/src/nwsapi/js:760:17))
at collect (node_modules/nwsapi/src/nwsapi/js:1552:21)
The text was updated successfully, but these errors were encountered: