Only trim spaces and tabs around header parameters

Merged
KL
11d ago
+28-3

parse_options_header trimmed parameter names and values with strip(), rstrip() and lstrip() without arguments. Those remove all Unicode whitespace, and because the header is decoded as latin-1, the bytes 0xA0 and 0x85 count as whitespace too. Whitespace around a header parameter is only a space or a tab (RFC 9110 §5.6.3).

HeaderBeforeAfter
form-data; name=voil\xc3\xa0name is voil\xc3name is voil\xc3\xa0
form-data; name="a";\xa0filename="a.txt"Has filename\xa0filename isn't filename, so the part is a field
multipart/form-data; boundary=XX\xa0Boundary is XXBoundary is XX\xa0

Spaces and tabs are still trimmed, and quoted values are unchanged.

AI Disclaimer

This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.