Strip whitespace around part header values in `FormParser`
Merged
KL
9h ago+20+20+01234567890123456789-1-1-0123456789
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