parse_mimetype: skip whitespace-only segments after a semicolon#13049
parse_mimetype: skip whitespace-only segments after a semicolon#13049HrachShah wants to merge 1 commit into
Conversation
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.
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Merging this PR will not alter performance
Comparing Footnotes
|
|
Superseded by #13052, which covers this case plus empty-key () and no-equals () segments. |
What changed
parse_mimetypenow skips whitespace-only segments after a;, matching thebehavior for the already-handled empty segment from a bare trailing
;.A MIME type like
text/html;previously produced{'': ''}in the parsedparameters; it now produces
{}.Why
Per RFC 2045 a MIME type parameter is a
token=valuepair, and a baretrailing
;was already being skipped as an empty segment. A;followedby 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; awhitespace-only string is truthy, so it slipped through. Switching to
if not item.strip(): continuehandles both cases the same way.Testing
test_parse_mimetype_skips_whitespace_only_segmentscoveringtrailing whitespace, tabs, OWS between a real parameter and the
trailing segment, and a real parameter that should still parse.
Closes #13009
Drafted with Zo Bot; reviewed by .