Skip to content

Do not submit <input type="reset"> as a form field - #281

Open
qianeric-backup wants to merge 1 commit into
Pylons:mainfrom
qianeric-backup:reset-input-not-submitted
Open

qianeric-backup wants to merge 1 commit into
Pylons:mainfrom
qianeric-backup:reset-input-not-submitted

Conversation

@qianeric-backup

Copy link
Copy Markdown

<input type="reset"> is submitted as a form field, so a real form.submit() posts data the browser never sends.

>>> app.get('/').forms[0].submit_fields()
[('text', 't'), ('clear', 'Clear')]

for a form containing <input name="text" value="t"> and <input type="reset" name="clear" value="Clear">. The resulting request body is text=t&clear=Clear.

<button type="reset"> in the same form is handled correctly and is not submitted. _parse_fields normalises it explicitly (webtest/forms.py:466):

            if tag == 'button':
                tag_type = 'submit'

and the registry just below registers the three button-ish types but not reset:

Field.classes['submit'] = Submit
Field.classes['button'] = Submit
Field.classes['image'] = Submit

reset falls through to the base Field, whose value is the value attribute, so submit_fields() keeps it. Submit.value__get returns None for these, and submit_fields() skips None values — that is the mechanism that already excludes <button type="reset">.

Treating buttons as submit controls is what this project does elsewhere: <button> was folded into Submit in 2.0.4 and <input type="image"> in 1.0. reset was simply missed.

Change

+Field.classes['reset'] = Submit

plus one word in the Submit docstring, two tests, and a changelog entry. No change to <input type="reset">'s value attribute — it stays readable through form.fields, it just is not submitted.

Verification

tree tests/test_forms.py full suite
main + the two new tests, webtest/forms.py unchanged 2 failed, 53 passed 2 failed, 250 passed
with this patch 55 passed 252 passed

The failures are [('field', 'value'), ('reset', 'Clear')] != [('field', 'value')] — the extra submitted field.

comm -3 between the failing-test lists of main and the patched tree is empty, and the difference against the red tree is exactly the two new ids. main is 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.lock constraint on it, no .pre-commit-config.yaml, no ruff/flake8/black config, and CI runs only uv run pytest, coverage report --fail-under=95 and sphinx-build -W -E. So I checked the same gates it does: coverage stays at 95% with --fail-under=95 exiting 0 (1550 → 1551 statements), and pycodestyle --max-line-length=79 and ruff --isolated --select E,F report the identical sets of findings before and after, with no new ones.

_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
qianeric-backup marked this pull request as ready for review November 27, 2026 23:39
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