Skip to content

parse_mimetype: skip whitespace-only segments after a semicolon#13049

Closed
HrachShah wants to merge 1 commit into
aio-libs:masterfrom
HrachShah:fix/13009-parse-mimetype-ws-only
Closed

parse_mimetype: skip whitespace-only segments after a semicolon#13049
HrachShah wants to merge 1 commit into
aio-libs:masterfrom
HrachShah:fix/13009-parse-mimetype-ws-only

Conversation

@HrachShah

Copy link
Copy Markdown

What changed

parse_mimetype now skips whitespace-only segments after a ;, matching the
behavior for the already-handled empty segment from a bare trailing ;.

A MIME type like text/html; previously produced {'': ''} in the parsed
parameters; it now produces {}.

Why

Per RFC 2045 a MIME type parameter is a token=value pair, and a bare
trailing ; was already being skipped as an empty segment. A ; followed
by whitespace was being treated as a parameter with an empty key, which is
not a valid MIME parameter. The check was if not item: continue; a
whitespace-only string is truthy, so it slipped through. Switching to
if not item.strip(): continue handles both cases the same way.

Testing

  • Added test_parse_mimetype_skips_whitespace_only_segments covering
    trailing whitespace, tabs, OWS between a real parameter and the
    trailing segment, and a real parameter that should still parse.
  • All pre-existing parse_mimetype tests continue to pass.

Closes #13009

Drafted with Zo Bot; reviewed by .

Trailing ';' followed by whitespace (e.g. "text/html; ") inserted a
spurious empty-key parameter in the parsed parameters dict, while a
bare trailing ';' was already correctly skipped. The check is now
'if not item.strip()' so whitespace-only segments are also skipped.
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Jul 3, 2026
@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.96%. Comparing base (85a150c) to head (c599730).
⚠️ Report is 18 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff            @@
##           master   #13049    +/-   ##
========================================
  Coverage   98.95%   98.96%            
========================================
  Files         131      131            
  Lines       48029    48162   +133     
  Branches     2495     2500     +5     
========================================
+ Hits        47529    47662   +133     
  Misses        376      376            
  Partials      124      124            
Flag Coverage Δ
Autobahn 22.22% <28.57%> (-0.05%) ⬇️
CI-GHA 98.90% <100.00%> (+<0.01%) ⬆️
OS-Linux 98.66% <100.00%> (+<0.01%) ⬆️
OS-Windows 97.04% <100.00%> (+0.01%) ⬆️
OS-macOS 97.95% <100.00%> (+<0.01%) ⬆️
Py-3.10 98.14% <100.00%> (+<0.01%) ⬆️
Py-3.11 98.41% <100.00%> (+<0.01%) ⬆️
Py-3.12 98.50% <100.00%> (+<0.01%) ⬆️
Py-3.13 98.48% <100.00%> (+0.01%) ⬆️
Py-3.14 98.50% <100.00%> (+<0.01%) ⬆️
Py-3.14t 97.58% <100.00%> (+<0.01%) ⬆️
Py-pypy-3.11 97.44% <100.00%> (+<0.01%) ⬆️
VM-macos 97.95% <100.00%> (+<0.01%) ⬆️
VM-ubuntu 98.66% <100.00%> (+<0.01%) ⬆️
VM-windows 97.04% <100.00%> (+0.01%) ⬆️
cython-coverage 38.11% <0.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@codspeed-hq

codspeed-hq Bot commented Jul 4, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 83 untouched benchmarks
⏩ 83 skipped benchmarks1


Comparing HrachShah:fix/13009-parse-mimetype-ws-only (c599730) with master (9d183e3)2

Open in CodSpeed

Footnotes

  1. 83 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on master (e3774b4) during the generation of this report, so 9d183e3 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@HrachShah

Copy link
Copy Markdown
Author

Superseded by #13052, which covers this case plus empty-key () and no-equals () segments.

@HrachShah HrachShah closed this Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parse_mimetype produces spurious empty-key parameter for whitespace-only segments after semicolons

1 participant