Skip to content

fix: accept HTAB after ';' in header parameters - #84

Closed
CLCK0622 wants to merge 1 commit into
defnull:mainfrom
CLCK0622:fix-htab-after-semicolon
Closed

CLCK0622 wants to merge 1 commit into
defnull:mainfrom
CLCK0622:fix-htab-after-semicolon

Conversation

@CLCK0622

Copy link
Copy Markdown

Header parameter parsing currently skips parameters when a semicolon is followed by a horizontal tab, dropping boundary, name, or filename. Accept SP and HTAB in that position, as specified by RFC 9110 §5.6.3 and §5.6.6. This lets strict form parsing read the same fields and uploads with tab-separated parameters as with space-separated parameters. The change keeps the existing handling around = and adds tests for boundary parsing, field names, filenames, and whitespace outside SP/HTAB.

Run this example from the repository root with Python 3.10 or later:

python - <<'PY'
from io import BytesIO
from multipart import MultipartError, parse_form_data, parse_options_header

content_type = "multipart/form-data;\tboundary=demo"
body = (
    b'--demo\r\nContent-Disposition: form-data; name="field"\r\n'
    b'\r\nok\r\n--demo--\r\n'
)
print(parse_options_header(content_type))
environ = {
    "REQUEST_METHOD": "POST",
    "CONTENT_TYPE": content_type,
    "CONTENT_LENGTH": str(len(body)),
    "wsgi.input": BytesIO(body),
}
try:
    forms, files = parse_form_data(environ, strict=True)
    print(dict(forms), dict(files))
except MultipartError as exc:
    print(type(exc).__name__ + ": " + str(exc))
PY

Before (5fd5a1a6ce05262181aa18b02e07e426491f7a0c):

('multipart/form-data', {})
ParserError: Missing boundary for multipart/form-data

After:

('multipart/form-data', {'boundary': 'demo'})
{'field': 'ok'} {}

Validation: python -m pytest -ra -q on macOS arm64 with CPython 3.12.13: 139 passed, 38 subtests passed. The unmodified suite passes before the change; the added tests expose 10 failing HTAB-related subtests before the fix. Linux and Python 3.10, 3.11, 3.13, and 3.14 were not rerun locally. The documentation and distribution CI jobs were not rerun locally.

AI disclosure: Codex assisted with part of the code and this description.

Header parameter parsing currently skips parameters when a semicolon is followed by a horizontal tab, dropping `boundary`, `name`, or `filename`. Accept SP and HTAB in that position, as specified by [RFC 9110 §5.6.3](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.6.3) and [§5.6.6](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.6.6). This lets strict form parsing read the same fields and uploads with tab-separated parameters as with space-separated parameters. The change keeps the existing handling around `=` and adds tests for boundary parsing, field names, filenames, and whitespace outside SP/HTAB.
Copilot AI balanced review requested due to automatic review settings October 27, 2026 16:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@defnull

defnull commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

Please elaborate why this is needed. Unless there is a HTTP client or library that actually emits headers with tabs instead of spaces (and breaks a SHOULD rule by doing so), I see no reason implementing random design mistakes from the past.

@CLCK0622

Copy link
Copy Markdown
Author

Thanks for reviewing this. My limited source review and public issue searches did not find a verifiable HTTP multipart client that automatically emits a tab immediately after the semicolon on the same header line. Without that evidence, I'll close this PR. Appreciate your time.

@CLCK0622 CLCK0622 closed this Oct 27, 2026
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.

3 participants