bigskysoftware / htmx

</> htmx - high power tools for HTML
https://htmx.org
Other
38.61k stars 1.31k forks source link

Fix illegal invocation for FormData proxy #2997

Closed scrhartley closed 2 weeks ago

scrhartley commented 3 weeks ago

Description

Currently the form data proxy has special handing for if the return value is a function, but not in the case where the key is a symbol. This omission can cause an error to be thrown.

Fixes constructor for URLSearchParams:

element.addEventListener('htmx:configRequest', function(event) {
    let params = new URLSearchParams(event.detail.parameters);
    console.log(params.toString());
});

If I was implementing this from fresh then I would use the more concise:

if (typeof result === 'function') {
    return result.bind(formData)
}

but instead I've replicated the existing approach:

if (typeof result === 'function') {
  return function() {
    return result.apply(formData, arguments)
  }
}

Corresponding issue: #2995

Testing

Added a new test to the existing ones for parameters.

Checklist

1cg commented 2 weeks ago

thank you!