Skip to content

Add public MIME type API, shortest encoding and minimal escaping - #17

Merged
snshn merged 1 commit into
masterfrom
public-mime-api-and-shortest-encoding-and-minimal-escaping
Oct 16, 2026
Merged

snshn merged 1 commit into
masterfrom
public-mime-api-and-shortest-encoding-and-minimal-escaping

Conversation

@snshn

@snshn snshn commented Oct 16, 2026

Copy link
Copy Markdown
Member

The WHATWG MIME type parser used for data URLs is now public as
dataurl::mime::MimeType (parse, essence, main_type, subtype, parameters,
charset, Display, FromStr), e.g. for parsing Content-Type headers.
DataUrl::mime_type() returns a MimeType, and DataUrl::set_mime_type()
sets the media type with all of its parameters from one.

How data gets serialized is now controlled by two settings:

  • DataEncoding (Percent, Base64, or Shortest, which picks whichever
    results in a shorter data URL), replacing is_base64_encoded() and
    set_is_base64_encoded()
  • Escaping (Full, the default, safe anywhere; or Minimal, which only
    escapes what would break double-quoted HTML attributes, CSS strings,
    and STYLE/SCRIPT elements), which keeps text formats like SVG short

Percent-encoding now also escapes "&", and trailing spaces always get
escaped, since URL parsers strip them.

@snshn
snshn merged commit e574523 into master Oct 16, 2026
9 checks passed
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.

1 participant