Skip to content

Commit a77903b

Browse files
committed
handle hx-select-oob escapped selector with .
1 parent 9558c79 commit a77903b

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

src/htmx.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1936,7 +1936,7 @@ var htmx = (function() {
19361936
const selector = oobSelectValue.shift().trim()
19371937
const oobValue = oobSelectValue.join(':') || 'true'
19381938
let oobElements
1939-
if (selector.indexOf('#') !== 0 && /^[a-z\-_][a-z0-9\-_]*$/i.test(selector)) {
1939+
if (selector.indexOf('#') !== 0 && /^[a-z\-_](\\\.|[a-z0-9\-_])*$/i.test(selector)) {
19401940
oobElements = fragment.querySelectorAll('#' + selector) // check if selector is an id first
19411941
}
19421942
if (!oobElements || !oobElements.length) {

test/attributes/hx-select-oob.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,17 @@ describe('hx-select-oob attribute', function() {
113113
div2.classList.contains('foo').should.equal(true)
114114
})
115115

116+
it('basic hx-select-oob works with CSS escaped id containing "."', function() {
117+
this.server.respondWith('GET', '/test', "<div id='d1'>foo</div><div id='my.div3'>bar</div>")
118+
var div = make('<div hx-get="/test" hx-select="#d1" hx-select-oob="my\\.div3"></div>')
119+
make('<div id="my.div3"></div>')
120+
div.click()
121+
this.server.respond()
122+
div.innerHTML.should.equal('<div id="d1">foo</div>')
123+
var div2 = byId('my.div3')
124+
div2.innerHTML.should.equal('bar')
125+
})
126+
116127
it('hx-select-oob can select multiple elements with a selector', function() {
117128
this.server.respondWith('GET', '/test', "<div id='d1'>foo</div><div class='foo' id='d2'>bar</div><div class='foo' id='d3'>baz</div>")
118129
var div = make('<div hx-get="/test" hx-select="#d1" hx-select-oob=".foo"></div>')

test/attributes/hx-swap.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ describe('hx-swap attribute', function() {
289289

290290
swapSpec(make("<div hx-swap='target:#table tbody'/>")).target.should.equal('#table tbody')
291291

292+
swapSpec(make("<div hx-swap='target:#table tbody swap:10s'/>")).target.should.equal('#table tbody')
293+
292294
swapSpec(make("<div hx-swap='customstyle settle:11 swap:10'/>")).swapStyle.should.equal('customstyle')
293295
})
294296

www/content/attributes/hx-select-oob.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ For example, to prepend the alert content instead of replacing it:
4646
## Notes
4747

4848
* `hx-select-oob` is inherited and can be placed on a parent element
49+
* the CSS selector used to locate the elements in the response can not contain a `:`

0 commit comments

Comments
 (0)