Skip to content

feat(form): reject empty field name in add_field_strict and add_file_strict#54

Merged
nao1215 merged 1 commit into
mainfrom
fix/issue-51-form-add-field-empty-name
May 20, 2026
Merged

feat(form): reject empty field name in add_field_strict and add_file_strict#54
nao1215 merged 1 commit into
mainfrom
fix/issue-51-form-add-field-empty-name

Conversation

@nao1215

@nao1215 nao1215 commented May 20, 2026

Copy link
Copy Markdown
Owner

Summary

multipartkit/form.add_field_strict and add_file_strict previously accepted an empty (or whitespace-only) name silently, producing a wire image with Content-Disposition: form-data; name="". RFC 7578 §4.2 requires the name parameter to be the field name itself; an empty value is implementation-defined at the receiver (skip, overwrite siblings keyed on "", or reject the body). The strict variants now reject it with the new Error(EmptyFieldName(value:)) variant on FormError, while the non-strict add_field / add_file keep their existing silent-accept behaviour for backward compatibility.

Changes

  • src/multipartkit/form.gleam: add EmptyFieldName(value:) variant to FormError; add_field_strict and add_file_strict now bool.guard on string.trim(name) == "" ahead of the existing CR/LF/NUL check and return Error(EmptyFieldName(value: name)); doc-comments on all four builders updated to spell out the RFC 7578 §4.2 non-empty name requirement and the strict-variant escape hatch.
  • test/regression_empty_field_name_test.gleam: new regression suite covering empty / whitespace-only / tab-only name rejection for both strict builders, empty filename still allowed by add_file_strict, non-empty name still works, and a backward-compatibility pin that non-strict add_field("", _) still silently accepts.
  • CHANGELOG.md: ## [Unreleased] / ### Added entry for the new variant and the strict-builder behaviour.

Design Decisions

Issue #51 listed three approaches (A: strict-Result reject, B: panic, C: docs-only). Approach A on the strict variants only — leaving non-strict behaviour intact — was chosen because the strict variants were introduced for exactly this kind of typed-error surfacing (#40, #41) and the non-strict variants have a documented silent-accept contract that callers may already rely on; a breaking change there would force every existing caller to migrate without a way to opt back into the old shape. The string.trim(name) == "" predicate covers both the bare empty string and whitespace-only inputs in a single branch, matching the Issue's acceptance criteria (" " must also reject). The empty-name guard runs before the control-byte guard so that a caller passing "" sees EmptyFieldName rather than the (technically also true) NameContainsControlBytes with the same empty payload. filename is intentionally left allowed-empty in add_file_strict because RFC 7578 §4.2 only constrains name.

Closes #51

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@nao1215 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 41 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 365c3121-6215-4f31-8d6c-0bd7d919dfc6

📥 Commits

Reviewing files that changed from the base of the PR and between ab187f8 and 2b3e9b6.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • src/multipartkit/form.gleam
  • test/regression_empty_field_name_test.gleam
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-51-form-add-field-empty-name

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nao1215 nao1215 merged commit b76922c into main May 20, 2026
5 checks passed
@nao1215 nao1215 deleted the fix/issue-51-form-add-field-empty-name branch May 20, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

form.add_field accepts empty name silently — RFC 7578 §4.2 says name MUST be field name

1 participant