Skip to content

fix(media-types): decode RFC 2231 percent-encoded octets correctly - #7384

Open
helmipradita wants to merge 1 commit into
denoland:mainfrom
helmipradita:fix/media-types-rfc2231-decoding
Open

helmipradita wants to merge 1 commit into
denoland:mainfrom
helmipradita:fix/media-types-rfc2231-decoding

Conversation

@helmipradita

Copy link
Copy Markdown

Fixes #7382.

Description

In @std/media-types, parseMediaType() and decode2331Encoding() previously decoded RFC 2231 percent-encoded values using JavaScript's native decodeURI(). Per RFC 2231 Section 4, %XX sequences represent raw octet byte values, and decodeURI() leaves reserved characters (such as %26 / &, %3B / ;, %2F / /, and %23 / #) percent-encoded. Additionally, when multi-byte UTF-8 sequences were split across parameter continuations (e.g. *0*=%E2%82 and *1*=%AC), calling decodeURI() on each continuation chunk threw URIError: URI malformed.

Changes

  1. Added percentDecode(v: string): Uint8Array in media_types/_util.ts to unescape %XX into raw byte octets.
  2. Updated decode2331Encoding() to decode unescaped octets using TextDecoder(charset).
  3. In parseMediaType(), joined byte chunks across continuation fragments before decoding with TextDecoder(), preventing URIError when multi-byte characters are split across continuations.
  4. Added test cases in media_types/parse_media_type_test.ts for RFC 2231 reserved characters and multi-byte continuation splits.

@codecov

codecov Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.01%. Comparing base (f834d02) to head (f9510d5).

Files with missing lines Patch % Lines
media_types/parse_media_type.ts 83.87% 3 Missing and 2 partials ⚠️
media_types/_util.ts 95.65% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7384      +/-   ##
==========================================
- Coverage   95.04%   95.01%   -0.03%     
==========================================
  Files         619      618       -1     
  Lines       52012    51798     -214     
  Branches     9450     9416      -34     
==========================================
- Hits        49434    49217     -217     
+ Misses       2031     2028       -3     
- Partials      547      553       +6     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@helmipradita

Copy link
Copy Markdown
Author

All 4 required checks are green on f9510d5 (plus full v1/v2 test matrix, lint, wasm, Codecov) and the PR is CLEAN/MERGEABLE. Open since 2026-11-07 with no reviews or reviewers assigned. @kt3k (approver on recent media-types work) could you take a look when you get a chance? Happy to address any feedback.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@std/media-types: parseMediaType leaves %26, %3B etc. encoded in RFC 2231 values and throws URIError on split UTF-8

1 participant