summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authoryoussame <youssefameachaq@gmail.com>2024-10-20 23:37:58 +0100
committerGitHub <noreply@github.com>2024-10-20 16:37:58 -0600
commit3e265ea263e4c55462e6be8506c765cb23ee3f46 (patch)
tree6f8b7e4a7682de2e227ee5e6a3cd91641937b612
parentf0964d2d0857198fa14f0263e29a4fc0026a3206 (diff)
downloadhtmx-3e265ea263e4c55462e6be8506c765cb23ee3f46.tar.gz
htmx-3e265ea263e4c55462e6be8506c765cb23ee3f46.zip
Fix TypeError on null path variable (#2967)
* Fix the error * add tests
-rw-r--r--src/htmx.js2
-rw-r--r--test/attributes/hx-boost.js26
2 files changed, 27 insertions, 1 deletions
diff --git a/src/htmx.js b/src/htmx.js
index f949da04..911b7dde 100644
--- a/src/htmx.js
+++ b/src/htmx.js
@@ -2323,7 +2323,7 @@ var htmx = (function() {
const rawAttribute = getRawAttribute(elt, 'method')
verb = (/** @type HttpVerb */(rawAttribute ? rawAttribute.toLowerCase() : 'get'))
path = getRawAttribute(elt, 'action')
- if (verb === 'get' && path.includes('?')) {
+ if (verb === 'get' && path && path.includes('?')) {
path = path.replace(/\?[^#]+/, '')
}
}
diff --git a/test/attributes/hx-boost.js b/test/attributes/hx-boost.js
index 20b49f63..2b1928f3 100644
--- a/test/attributes/hx-boost.js
+++ b/test/attributes/hx-boost.js
@@ -143,4 +143,30 @@ describe('hx-boost attribute', function() {
this.server.respond()
div.innerHTML.should.equal('Boosted!')
})
+
+ it('form get with an unset action property', function() {
+ this.server.respondWith('GET', /\/*/, function(xhr) {
+ should.equal(undefined, getParameters(xhr).foo)
+ xhr.respond(200, {}, 'Boosted!')
+ })
+
+ var div = make('<div hx-target="this" hx-boost="true"><form id="f1" method="get"><button id="b1">Submit</button></form></div>')
+ var btn = byId('b1')
+ btn.click()
+ this.server.respond()
+ div.innerHTML.should.equal('Boosted!')
+ })
+
+ it('form get with an empty action property', function() {
+ this.server.respondWith('GET', /\/*/, function(xhr) {
+ should.equal(undefined, getParameters(xhr).foo)
+ xhr.respond(200, {}, 'Boosted!')
+ })
+
+ var div = make('<div hx-target="this" hx-boost="true"><form id="f1" action="" method="get"><button id="b1">Submit</button></form></div>')
+ var btn = byId('b1')
+ btn.click()
+ this.server.respond()
+ div.innerHTML.should.equal('Boosted!')
+ })
})