Skip to content

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

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

[PR #13010/9e00085c backport][3.14] Fix parse_mimetype producing spurious empty-key parameter for whitespace-only segments after semicolons#13096
Dreamsorcerer merged 1 commit into
3.14from
patchback/backports/3.14/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 (e1cad97) to head (becc4eb).
⚠️ Report is 2 commits behind head on 3.14.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             3.14   #13096   +/-   ##
=======================================
  Coverage   98.24%   98.24%           
=======================================
  Files         135      135           
  Lines       48824    48824           
  Branches     2619     2619           
=======================================
+ Hits        47966    47967    +1     
  Misses        678      678           
+ Partials      180      179    -1     
Flag Coverage Δ
CI-GHA 98.29% <100.00%> (+<0.01%) ⬆️
OS-Linux 98.06% <100.00%> (+<0.01%) ⬆️
OS-Windows 95.73% <100.00%> (-0.01%) ⬇️
OS-macOS 97.26% <100.00%> (ø)
Py-3.10 97.45% <100.00%> (ø)
Py-3.11 97.72% <100.00%> (ø)
Py-3.12 97.80% <100.00%> (ø)
Py-3.13 97.79% <100.00%> (+<0.01%) ⬆️
Py-3.14 97.89% <100.00%> (-0.01%) ⬇️
Py-3.14t 96.89% <100.00%> (+<0.01%) ⬆️
Py-pypy-3.11 96.74% <100.00%> (-0.01%) ⬇️
VM-macos 97.26% <100.00%> (ø)
VM-ubuntu 98.06% <100.00%> (+<0.01%) ⬆️
VM-windows 95.73% <100.00%> (-0.01%) ⬇️
cython-coverage 38.43% <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

✅ 72 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing patchback/backports/3.14/9e00085c958fbcd40de37867e773bf7cd3bbee0c/pr-13010 (becc4eb) with 3.14 (e1cad97)

Open in CodSpeed

Footnotes

  1. 7 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 d0b9752 into 3.14 Jul 8, 2026
65 of 83 checks passed
@Dreamsorcerer Dreamsorcerer deleted the patchback/backports/3.14/9e00085c958fbcd40de37867e773bf7cd3bbee0c/pr-13010 branch July 8, 2026 10:30
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