Skip to content

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

Draft
HrachShah wants to merge 2 commits into
aio-libs:masterfrom
HrachShah:patch-13009-mimetype
Draft

parse_mimetype: skip whitespace-only segments after a semicolon#13058
HrachShah wants to merge 2 commits into
aio-libs:masterfrom
HrachShah:patch-13009-mimetype

Conversation

@HrachShah

Copy link
Copy Markdown

What do these changes do?

A trailing semicolon followed by whitespace (e.g. text/html; or text/html;\t) used to be split into a parameter segment that is truthy but contains only whitespace, and parse_mimetype would add it to the parsed parameters dict as {'': ''}. The pre-existing if not item: continue check only handled the case of a bare trailing ;.

The fix changes the check to if not item.strip() so whitespace-only segments are also treated as no-op, matching the RFC 2045 view that there is no parameter — only a delimiter followed by nothing.

The pre-existing application/json; charset=utf-8; test (a real parameter followed by a bare trailing ;) still produces {'charset': 'utf-8'} and is unaffected by this change.

Are there changes in behavior for the user?

Yes. parse_mimetype callers that read parameters via .get('charset') no longer see the spurious empty-key entry {'': ''} from text/html; style inputs. The behaviour for text/html; (a bare trailing semicolon, which was already correctly producing {}) is preserved.

Is it a substantial burden for the maintainers to support this?

No. One-line change in parse_mimetype. No public API changes.

Related issue number

Fixes #13009

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • New feature: a news fragment is added
  • CI passes
Drafted with Zo Bot; reviewed by HrachShah.

Drafted with Zo Bot; reviewed by HrachShah.

@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Jul 6, 2026
@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.96%. Comparing base (e3774b4) to head (5994311).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #13058   +/-   ##
=======================================
  Coverage   98.96%   98.96%           
=======================================
  Files         131      131           
  Lines       48156    48156           
  Branches     2499     2499           
=======================================
  Hits        47656    47656           
  Misses        376      376           
  Partials      124      124           
Flag Coverage Δ
Autobahn 22.21% <0.00%> (ø)
CI-GHA 98.90% <100.00%> (ø)
OS-Linux 98.67% <100.00%> (ø)
OS-Windows 97.04% <100.00%> (-0.01%) ⬇️
OS-macOS 97.94% <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%> (ø)
Py-3.13 98.47% <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.45% <100.00%> (ø)
VM-macos 97.94% <100.00%> (-0.01%) ⬇️
VM-ubuntu 98.67% <100.00%> (ø)
VM-windows 97.04% <100.00%> (-0.01%) ⬇️
cython-coverage 38.11% <0.00%> (ø)

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 6, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 83 untouched benchmarks
⏩ 83 skipped benchmarks1


Comparing HrachShah:patch-13009-mimetype (5994311) with master (e3774b4)

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.

@HrachShah HrachShah force-pushed the patch-13009-mimetype branch from 4b9457b to e8e099b Compare July 6, 2026 03:47
@HrachShah HrachShah force-pushed the patch-13009-mimetype branch from e8e099b to 5a2cac2 Compare July 6, 2026 03:48
@HrachShah HrachShah force-pushed the patch-13009-mimetype branch from 5a2cac2 to 5994311 Compare July 6, 2026 03:54
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