Repository navigation
Do not submit <input type="reset"> as a form field - #281
Open
qianeric-backup wants to merge 1 commit into
Open
qianeric-backup wants to merge 1 commit into
qianeric-backup wants to merge 1 commit into
Conversation
_parse_fields normalises <button type="reset"> to a submit control, but the Field.classes registry never registers "reset", so <input type="reset"> falls through to Field and its value attribute is posted as form data. Browsers never send a reset button. Register it as Submit, as <button> and <input type="image"> already are, so its value stays readable but is not submitted.
qianeric-backup
marked this pull request as ready for review
November 27, 2026 23:39
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
<input type="reset">is submitted as a form field, so a realform.submit()posts data the browser never sends.for a form containing
<input name="text" value="t">and<input type="reset" name="clear" value="Clear">. The resulting request body istext=t&clear=Clear.<button type="reset">in the same form is handled correctly and is not submitted._parse_fieldsnormalises it explicitly (webtest/forms.py:466):and the registry just below registers the three button-ish types but not
reset:resetfalls through to the baseField, whosevalueis thevalueattribute, sosubmit_fields()keeps it.Submit.value__getreturnsNonefor these, andsubmit_fields()skipsNonevalues — that is the mechanism that already excludes<button type="reset">.Treating buttons as submit controls is what this project does elsewhere:
<button>was folded intoSubmitin 2.0.4 and<input type="image">in 1.0.resetwas simply missed.Change
+Field.classes['reset'] = Submitplus one word in the
Submitdocstring, two tests, and a changelog entry. No change to<input type="reset">'svalueattribute — it stays readable throughform.fields, it just is not submitted.Verification
tests/test_forms.pymain+ the two new tests,webtest/forms.pyunchanged2 failed, 53 passed2 failed, 250 passed55 passed252 passedThe failures are
[('field', 'value'), ('reset', 'Clear')] != [('field', 'value')]— the extra submitted field.comm -3between the failing-test lists ofmainand the patched tree is empty, and the difference against the red tree is exactly the two new ids.mainis green on its own, so there are no pre-existing failures to account for.Thirteen groups of legal calls (text/password/hidden/email, textarea, select with an invalid value, multi-select, radio, a checkbox list including one without a
value, two same-named submits,<button>,type=button,type=image,<button type="reset">as a regression guard,submit_fields()plus the real POST body,form.lint(), file uploads, and button reprs) produce identical transcripts before and after.The repository pins no linter — no
uv.lockconstraint on it, no.pre-commit-config.yaml, no ruff/flake8/black config, and CI runs onlyuv run pytest,coverage report --fail-under=95andsphinx-build -W -E. So I checked the same gates it does: coverage stays at 95% with--fail-under=95exiting 0 (1550 → 1551 statements), andpycodestyle --max-line-length=79andruff --isolated --select E,Freport the identical sets of findings before and after, with no new ones.