Skip to content

Strip whitespace around part header values in FormParser - #366

Merged
Kludex merged 2 commits into
mainfrom
strip-part-header-whitespace
Nov 12, 2026
Merged

Kludex merged 2 commits into
mainfrom
strip-part-header-whitespace

Conversation

@Kludex

@Kludex Kludex commented Nov 11, 2026 •

Copy link
Copy Markdown
Owner

FormParser kept the spaces and tabs around a part header value, so Content-Transfer-Encoding: base64 (trailing space) or Content-Transfer-Encoding: base64 (tab) was treated as an unknown encoding, and the field was delivered still encoded.

from python_multipart import FormParser

body = (
    b"--b\r\n"
    b'Content-Disposition: form-data; name="f"\r\n'
    b"Content-Transfer-Encoding: base64 \r\n"
    b"\r\n"
    b"aGVsbG8=\r\n"
    b"--b--\r\n"
)
fields = []
parser = FormParser("multipart/form-data", lambda f: fields.append(f.value), None, boundary=b"b")
parser.write(body)
parser.finalize()
print(fields)  # before: [b'aGVsbG8='], after: [b'hello']

RFC 9110 §5.5 excludes leading and trailing whitespace from a field value. Only spaces and tabs are stripped, matching #364. The low-level MultipartParser callbacks still receive the raw bytes.

Session: pi --session 01a1cc04-bb37-7152-92e5-03b3625b499e

View guided diff

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T20:23:59.232925Z 0eae2c0 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 3 files

View guided diff | Re-trigger cubic

@Kludex Kludex closed this Nov 11, 2026
@Kludex Kludex reopened this Nov 11, 2026
@codspeed

codspeed Bot commented Nov 12, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 5 untouched benchmarks


Comparing strip-part-header-whitespace (c9ea84a) with main (6cebfd8)

Open in CodSpeed

@Kludex
Kludex merged commit 9bd038e into main Nov 12, 2026
14 checks passed
@Kludex
Kludex deleted the strip-part-header-whitespace branch November 12, 2026 08:18
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