Skip to content

Commit

Permalink
Handle Space before comma in Trigger Spec (#2903)
Browse files Browse the repository at this point in the history
* strip space after trigger spec

* Add test

* handle addiional case
  • Loading branch information
MichaelWest22 authored Sep 25, 2024
1 parent 3d1a2e5 commit d528c9d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -2171,8 +2171,8 @@ var htmx = (function() {
if (eventFilter) {
triggerSpec.eventFilter = eventFilter
}
consumeUntil(tokens, NOT_WHITESPACE)
while (tokens.length > 0 && tokens[0] !== ',') {
consumeUntil(tokens, NOT_WHITESPACE)
const token = tokens.shift()
if (token === 'changed') {
triggerSpec.changed = true
Expand Down Expand Up @@ -2217,6 +2217,7 @@ var htmx = (function() {
} else {
triggerErrorEvent(elt, 'htmx:syntax:error', { token: tokens.shift() })
}
consumeUntil(tokens, NOT_WHITESPACE)
}
triggerSpecs.push(triggerSpec)
}
Expand Down
15 changes: 15 additions & 0 deletions test/attributes/hx-trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -1079,4 +1079,19 @@ describe('hx-trigger attribute', function() {

htmx.config.triggerSpecsCache = initialCacheConfig
})

it('handles spaces at the end of trigger specs', function() {
var requests = 0
this.server.respondWith('GET', '/test', function(xhr) {
requests++
xhr.respond(200, {}, 'Requests: ' + requests)
})
var div = make('<div hx-trigger="load , click consume " hx-get="/test">Requests: 0</div>')
div.innerHTML.should.equal('Requests: 0')
this.server.respond()
div.innerHTML.should.equal('Requests: 1')
div.click()
this.server.respond()
div.innerHTML.should.equal('Requests: 2')
})
})

0 comments on commit d528c9d

Please sign in to comment.