-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
Pagination classes with special characters aren't escaped. Throws a DOMException #4403
Comments
Hi! Thanks for your investigation and solutions, appreciate it. I have decided to go with solution 1 for now, at least it looks safest for now :) |
again an issue in 11.1.4 |
yes, i can confirm, we're also experiencing errors when using multiple tailwindcss utilities in pagination classes
|
@nolimits4web
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What You Did
Use tailwind classes in bullet pagination config that contain nonstandard/special characters:
.
when followed by a number. E.g.w-2.5
:
, E.g.sm:w-2
/
E.g.w-1/2
Reproduction + implemented all possible solutions mentioned below.
https://stackblitz.com/edit/swiper-demo-1-default-ndmkbc?devtoolsheight=33&file=index.js
Expected Behavior
It shouldn't error out and work just like you'd expect.
Actual Behavior
It's erroring out with an
Uncaught DOMException: Failed to execute 'querySelectorAll' on 'Element': ... is not a valid selector.
Additional Info
I think this might be better if it was in dom7. Since it ultimately goes through dom7's find method, it makes sense to escape there which makes it easier for devs since they don't have to deal with escaping. The only special character that's slightly tricky is
.
.Using
w-2.5 sm:w-1/2
as an example, swiper js is going to pass.w-2.5.sm:w-1/2
to dom7. Dom7 would then escape:.
(only if it's immediately followed by a digit):
/
This should handle most cases and 100% of tailwind.
Dom7 Solution
Regex demo/test - https://regex101.com/r/DhAilO/1/
Aside from the
find
method in dom7, I'm not sure if other methods will need refactoring.Or, Swiper Solution
Solution #1
Escape the known problematic characters. Other than that, it's the same thing that's already in place.
Solution #2
Less regex. Easier to read. Probably covers more characters than solution 1.
Less browser support and experimental but it meets the requirements listed in swiper's package.json.
https://developer.mozilla.org/en-US/docs/Web/API/CSS/escape
Other helpful things
Docs about escaping special characters
https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector#escaping_special_characters
Relevant Lines I Found
https://github.com/nolimits4web/swiper/blob/v6.5.3/src/components/pagination/pagination.js#L221
https://github.com/nolimits4web/swiper/blob/v6.5.3/src/components/pagination/pagination.js#L276
https://github.com/nolimits4web/swiper/blob/v6.5.3/src/components/pagination/pagination.js#L305
https://github.com/nolimits4web/swiper/blob/v6.5.3/src/components/a11y/a11y.js#L76
https://github.com/nolimits4web/swiper/blob/v6.5.3/src/components/a11y/a11y.js#L214
https://github.com/nolimits4web/swiper/blob/v6.5.3/src/components/a11y/a11y.js#L248
The text was updated successfully, but these errors were encountered: