Skip to content
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

Fixes issue 1537 - OOB does not escape query selector #2319

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

FraserChapman
Copy link

@FraserChapman FraserChapman commented Feb 15, 2024

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:

#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

  • I have read the contribution guidelines
  • I have targeted this PR against the correct branch (master for website changes, dev for
    source changes)
  • This is either a bugfix, a documentation update, or a new feature that has been explicitly
    approved via an issue
  • I ran the test suite locally (npm run test) and verified that it succeeded

@Telroshan Telroshan added the enhancement New feature or request label Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants