[codex] Validate form submitters#82
Conversation
Validate encode(form, { submitter }) before serializing controls so non-submit controls throw a TypeError and submit buttons owned by another form throw a NotFoundError-style DOMException.
Add regression coverage for invalid submitters and assert valid submit buttons are included exactly once.
Greptile SummaryThis PR adds upfront submitter validation to
Confidence Score: 5/5Safe to merge — the new validation is a straightforward upfront guard with no changes to the encoding logic itself. The implementation is correct: isSubmitButton already guarantees the element is an HTMLButtonElement or HTMLInputElement before the ownership check runs, error types match the spec, and the form-attribute edge case is handled correctly through element.form. No encoding paths were altered. test/client.test.ts — the sentinel re-throw lives inside the same try block as the call under test.
|
| Filename | Overview |
|---|---|
| src/encode.ts | Adds validateSubmitter() called upfront in encodeForm(); correctly throws TypeError for non-submit controls and DOMException("NotFoundError") for submit buttons not owned by the form. |
| test/client.test.ts | Adds tests for the three new rejection scenarios; "rejects submit buttons not owned by the form" uses a try/catch pattern with a sentinel re-throw that is caught by the same block, which can produce misleading assertion failures on regression. |
| .changeset/validate-form-submitter.md | Adds a patch changeset entry accurately describing the new submitter validation behaviour. |
Reviews (2): Last reviewed commit: "test: assert cross-form submitter error" | Re-trigger Greptile
Strengthen the Issue #69 regression coverage by asserting cross-form submitters throw a DOMException named NotFoundError, matching the encoder contract and native FormData behavior.
Summary
Fixes #69.
This updates
encode(form, { submitter })to validate the submitter before walking form controls, matching nativeFormData(form, submitter)behavior more closely.Root Cause
submitterwas only compared while handling submit buttons in the form element loop. That meant non-submit controls and submit buttons owned by a different form were never rejected up front, so encoding continued and returned normal entries.Changes
submitterwithTypeError.NotFoundErrorDOMExceptionwhere available.Validation
bun fmtbun lint:fixbun run testbun typecheck