0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-03-10 23:01:26 -05:00

fixes property shadowing for form.attributes (#13313)

Co-authored-by: ematipico <602478+ematipico@users.noreply.github.com>
This commit is contained in:
Martin Trapp 2025-02-26 11:55:01 +01:00 committed by GitHub
parent 2cdeaea64c
commit 9e7c71d19c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fixes an issue where a form field named "attributes" shadows the form.attributes property.

View file

@ -12,5 +12,6 @@ export const prerender = false;
<input type="hidden" name="name" value="Testing" />
{postShowThrow ? <input type="hidden" name="throw" value="true" /> : ''}
<input type="submit" value="Submit" id="submit" />
<input type="text" name="attributes" />
</form>
</Layout>

View file

@ -397,8 +397,7 @@ async function transition(
//
// Note: getNamedItem can return null in real life, even if TypeScript doesn't think so, hence
// the ?.
init.body =
form?.attributes.getNamedItem('enctype')?.value === 'application/x-www-form-urlencoded'
init.body = (from !== undefined && Reflect.get(HTMLFormElement.prototype, "attributes", form).getNamedItem('enctype')?.value === 'application/x-www-form-urlencoded')
? new URLSearchParams(preparationEvent.formData as any)
: preparationEvent.formData;
}