mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-09-27 04:50:43 +00:00
Fixes issue 1537 - OOB does not escape query selector - updated version (#3304)
* Fixes issue 1537 - OOB does not escape query selector * Adds test cases for oob swaps where the id contains special characters * Updated oob multiple elements with the same ID test * fix(issue-1537): resolved conflicts with master * fix(issue-1537): fixed codestyle issues --------- Co-authored-by: Fraser Chapman <fraser.chapman@gmail.com> Co-authored-by: David Martiník <david.martinik@powerflow.cz>
This commit is contained in:
parent
8409ebca3b
commit
730bd8224d
@ -1444,7 +1444,7 @@ var htmx = (function() {
|
||||
*/
|
||||
function oobSwap(oobValue, oobElement, settleInfo, rootNode) {
|
||||
rootNode = rootNode || getDocument()
|
||||
let selector = '#' + getRawAttribute(oobElement, 'id')
|
||||
let selector = '#' + CSS.escape(getRawAttribute(oobElement, 'id'))
|
||||
/** @type HtmxSwapStyle */
|
||||
let swapStyle = 'outerHTML'
|
||||
if (oobValue === 'true') {
|
||||
|
@ -364,4 +364,27 @@ describe('hx-swap-oob attribute', function() {
|
||||
div.click()
|
||||
this.server.respond()
|
||||
})
|
||||
|
||||
it('handles elements with IDs containing special characters properly', function() {
|
||||
this.server.respondWith('GET', '/test', '<div id="foo-/bar/" hx-swap-oob="innerHTML">Swapped10</div>')
|
||||
var div = make('<div hx-get="/test">click me</div>')
|
||||
make('<div id="foo-/bar/">Existing Content</div>')
|
||||
div.click()
|
||||
this.server.respond()
|
||||
var swappedElement = document.querySelector('[id="foo-/bar/"]')
|
||||
swappedElement.innerHTML.should.equal('Swapped10')
|
||||
})
|
||||
|
||||
it('handles one swap into multiple elements with the same ID properly', function() {
|
||||
this.server.respondWith('GET', '/test', '<div id="foo-/bar/" hx-swap-oob="innerHTML">Swapped11</div>')
|
||||
var div = make('<div hx-get="/test">click me</div>')
|
||||
make('<div id="foo-/bar/">Existing Content 1</div>')
|
||||
make('<div id="foo-/bar/">Existing Content 2</div>')
|
||||
div.click()
|
||||
this.server.respond()
|
||||
var swappedElements = document.querySelectorAll('[id="foo-/bar/"]')
|
||||
swappedElements.forEach(function(element) {
|
||||
element.innerHTML.should.equal('Swapped11')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user