htmx
htmx copied to clipboard
Fixes issue 1537 - OOB does not escape query selector
Description
This change alters how the oobSwap function builds the query selector string. Rather than simply prefixing it with a # it uses the '[id="raw_id"]' format. Where raw_id is the value obtained from getRawAttribute(oobElement, "id")
Ideally this could be done more cleanly with template literals (backtick strings) - but as I understand it you want to support IE11.
This fix allows the call querySelectorAll to return the nodelist of all elements with the ids such as "foo-/bar" - without getting "Failed to execute 'querySelectorAll' on 'Document': '#foo-/bar' is not a valid selector, and whilst not limiting the selection to the first matching id in the document.
Corresponding issue:
https://github.com/bigskysoftware/htmx/issues/1537
Testing
I ran the htmx.js test suite Version: 1.9.10 and got 0 failures I also manually tested ids such as "foo-/bar" and it all seems to be working as expected.
Further to this I've added test cases for
'handles elements with IDs containing special characters properly'
and
'handles one swap into multiple elements with the same ID properly'
And re- ran the htmx.js test suite Version: 1.9.10 and got 0 failures
Checklist
- [x] I have read the contribution guidelines
- [x] I have targeted this PR against the correct branch (
masterfor website changes,devfor source changes) - [x] This is either a bugfix, a documentation update, or a new feature that has been explicitly approved via an issue
- [x] I ran the test suite locally (
npm run test) and verified that it succeeded
Hey @FraserChapman , following up late on this (sorry about that!) If you are still interested in this change, could you resolve conflicts?
as I understood it htmx v1 maintains support for Internet Explorer 11 and CSS.escape isn't supported.
Since then, we released htmx 2 which dropped IE11 support, so feel free to use that method if you want 😄
Hi @FraserChapman, could you, please, finish this PR? It just needs to resolve conflicts, or should I take over?
@MAW016 My understanding it was it wasn't wanted/required based on the previous messages. Apologies for the confusion/misunderstanding - happy for you to take it over.
a newer version of this PR just merged so we can close this duplicate now
@MichaelWest22 Many thanks for picking this up, sorry it seemed to slip through the cracks for so long!