Skip to content

[PR #13010/9e00085c backport][3.15] Fix parse_mimetype producing spurious empty-key parameter for whitespace-only segments after semicolons#13097

Merged
Dreamsorcerer merged 1 commit into
3.15from
patchback/backports/3.15/9e00085c958fbcd40de37867e773bf7cd3bbee0c/pr-13010
Jul 8, 2026
Merged

[PR #13010/9e00085c backport][3.15] Fix parse_mimetype producing spurious empty-key parameter for whitespace-only segments after semicolons#13097
Dreamsorcerer merged 1 commit into
3.15from
patchback/backports/3.15/9e00085c958fbcd40de37867e773bf7cd3bbee0c/pr-13010

Conversation

@patchback

@patchback patchback Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

This is a backport of PR #13010 as merged into master (9e00085).

Summary

parse_mimetype incorrectly adds a spurious {'': ''} parameter entry when a MIME type string has a trailing semicolon followed by whitespace (e.g. 'text/html; ').

Closes #13009

Root cause

aiohttp/helpers.py splits on ; and skips empty segments with:

if not item:
    continue

A bare trailing ; (like text/html;) produces an empty-string segment, which is correctly skipped. But text/html; produces a whitespace-only segment (' ') which is truthy — so it is NOT skipped — and ends up as params.add('', '').

Fix

-        if not item:
+        if not item.strip():

Reproduction / before

from aiohttp.helpers import parse_mimetype

dict(parse_mimetype('text/html; ').parameters)         # {'': ''}  ← wrong
dict(parse_mimetype('text/html;  ').parameters)        # {'': ''}  ← wrong
dict(parse_mimetype('text/html;\t').parameters)        # {'': ''}  ← wrong
dict(parse_mimetype('text/html; charset=utf-8; ').parameters)  # {'charset': 'utf-8', '': ''}  ← wrong

After fix

All four return the expected values with no empty-key parameter.

Testing

Four new parametrize cases added to tests/test_helpers.py::test_parse_mimetype. All 141 existing tests continue to pass.

…ace-only segments after semicolons (#13010)

(cherry picked from commit 9e00085)
@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.24%. Comparing base (4078e04) to head (f67e98f).
⚠️ Report is 1 commits behind head on 3.15.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             3.15   #13097   +/-   ##
=======================================
  Coverage   98.24%   98.24%           
=======================================
  Files         135      135           
  Lines       48920    48920           
  Branches     2632     2632           
=======================================
  Hits        48062    48062           
  Misses        678      678           
  Partials      180      180           
Flag Coverage Δ
CI-GHA 98.27% <100.00%> (-0.01%) ⬇️
OS-Linux 98.04% <100.00%> (-0.01%) ⬇️
OS-Windows 95.72% <100.00%> (-0.01%) ⬇️
OS-macOS 97.25% <100.00%> (+<0.01%) ⬆️
Py-3.10 97.41% <100.00%> (-0.01%) ⬇️
Py-3.11 97.71% <100.00%> (+<0.01%) ⬆️
Py-3.12 97.78% <100.00%> (ø)
Py-3.13 97.76% <100.00%> (-0.01%) ⬇️
Py-3.14 97.87% <100.00%> (-0.01%) ⬇️
Py-3.14t 96.88% <100.00%> (+<0.01%) ⬆️
Py-pypy-3.11 96.72% <100.00%> (-0.01%) ⬇️
VM-macos 97.25% <100.00%> (+<0.01%) ⬆️
VM-ubuntu 98.04% <100.00%> (-0.01%) ⬇️
VM-windows 95.72% <100.00%> (-0.01%) ⬇️
cython-coverage 38.41% <0.00%> (+<0.01%) ⬆️

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

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 83 untouched benchmarks
⏩ 86 skipped benchmarks1


Comparing patchback/backports/3.15/9e00085c958fbcd40de37867e773bf7cd3bbee0c/pr-13010 (f67e98f) with 3.15 (4078e04)

Open in CodSpeed

Footnotes

  1. 86 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.

@Dreamsorcerer Dreamsorcerer merged commit 63157f5 into 3.15 Jul 8, 2026
46 checks passed
@Dreamsorcerer Dreamsorcerer deleted the patchback/backports/3.15/9e00085c958fbcd40de37867e773bf7cd3bbee0c/pr-13010 branch July 8, 2026 01:25
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.

2 participants