htmx icon indicating copy to clipboard operation
htmx copied to clipboard

Fixes issue 1537 - OOB does not escape query selector

Open FraserChapman opened this issue 1 year ago • 1 comments

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 (master for website changes, dev for 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

FraserChapman avatar Feb 15 '24 15:02 FraserChapman