mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-09-26 20:40:41 +00:00
Fix illegal invocation for FormData proxy (#2997)
Fix illegal invocation for a FormData proxy returning a function looked-up via a symbol Co-authored-by: shartley <scrhartley@github.com>
This commit is contained in:
parent
816fe6d161
commit
62969122f1
10
src/htmx.js
10
src/htmx.js
@ -4039,7 +4039,15 @@ var htmx = (function() {
|
||||
get: function(target, name) {
|
||||
if (typeof name === 'symbol') {
|
||||
// Forward symbol calls to the FormData itself directly
|
||||
return Reflect.get(target, name)
|
||||
const result = Reflect.get(target, name)
|
||||
// Wrap in function with apply to correctly bind the FormData context, as a direct call would result in an illegal invocation error
|
||||
if (typeof result === 'function') {
|
||||
return function() {
|
||||
return result.apply(formData, arguments)
|
||||
}
|
||||
} else {
|
||||
return result
|
||||
}
|
||||
}
|
||||
if (name === 'toJSON') {
|
||||
// Support JSON.stringify call on proxy
|
||||
|
@ -288,6 +288,14 @@ describe('Core htmx Parameter Handling', function() {
|
||||
vals.foo.should.equal('null')
|
||||
})
|
||||
|
||||
it('formdata can be used to construct a URLSearchParams instance', function() {
|
||||
var form = make('<input name="foo" value="bar"/>')
|
||||
var vals = htmx._('getInputValues')(form, 'get').values
|
||||
function makeSearchParams() { return new URLSearchParams(vals).toString() }
|
||||
makeSearchParams.should.not.throw()
|
||||
makeSearchParams().should.equal('foo=bar')
|
||||
})
|
||||
|
||||
it('order of parameters follows order of input elements', function() {
|
||||
this.server.respondWith('GET', '/test?foo=bar&bar=foo&foo=bar&foo2=bar2', function(xhr) {
|
||||
xhr.respond(200, {}, 'Clicked!')
|
||||
|
Loading…
x
Reference in New Issue
Block a user