Skip to content

Validate form encoding before replacing request body state - #332

Open
OskarEichler wants to merge 1 commit into
ruby:masterfrom
OskarEichler:codex/form-http
Open

Validate form encoding before replacing request body state#332
OskarEichler wants to merge 1 commit into
ruby:masterfrom
OskarEichler:codex/form-http

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Validate the enctype before replacing body/form state. Keep the assignments inside the accepted branch, preserving valid-form behavior and return value.

Reproduction

With req = Net::HTTP::Post.new('/'); req.body = 'keep', call req.set_form([['name', 'value']], 'wrong') and rescue ArgumentError. Before, req.body becomes nil; after, it remains keep. The same problem affects existing body_stream and multipart form state.

Verification

  • Ruby 4.0.6 through rbenv; existing bundle exec rake test: 201 tests, 914 assertions, zero failures/errors, both baseline and this isolated patch.
  • 8 focused checks cover invalid enctype errors and preserved string/stream/form state, plus valid replacement and Content-Type behavior.
  • Ruby syntax and git diff --check pass. Supplemental Lint scan retains the same 25 pre-existing findings; no new findings by file/cop.
  • No test/spec files were added or modified, per this contribution's explicit no-new-tests constraint. Focused reproductions were run externally.

Compatibility and limitations

No API or dependency change. Intentional error-path correction: a rejected enctype no longer discards the existing request body.

Based on master 23e859e92e10e43cad520fcacac3fd43640dba7b. Optional external OpenSSL tests and other Ruby/OS combinations were not run. Existing related issues/PRs were checked; this is a focused correctness change, not a claim of exhaustive coverage.

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.

1 participant