Skip to content

Respect MIME type aliases - #171

Merged
jeremy merged 1 commit into
mainfrom
respect-mime-type-aliases
Aug 20, 2026
Merged

jeremy merged 1 commit into
mainfrom
respect-mime-type-aliases

Conversation

@jeremy

@jeremy jeremy commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

Supersedes #101 (2024's aliases branch, re-implemented on current main — the merge base predates the HTML rework, the security stack, the validating generator, and the zip sniffer). Closes #84.

What

Model Tika's type aliases instead of discarding them. The generated tables gain a TYPE_ALIASES map — 152 aliases extracted from the data's <alias> elements, downcased to match Marcel's lowercase-normalized lookups — and alias resolution reaches every API:

  • Declared types resolve to canonical: application/javascript → text/javascript, audio/x-aac → audio/aac, and so on across the table.
  • Magic.child? resolves aliases on both sides and through the parent graph, so parents declared via an alias (as Tika does for X bitmap's text/x-c) work without hand-maintained overrides — custom.xml's workaround pinning image/x-xbitmap to text/x-csrc is removed, closing that file's standing TODO.
  • Magic.canonical / Magic.by_type / Magic#canonical expose resolution directly. Class-level canonical is allocation-free for normalized input — measured 0 allocations/call lowercase, with child? holding at its preexisting 2 (traversal array + visited hash) — since child? resolves every node it visits.

Alias direction is data, not policy

Audited all 152 Tika aliases against IANA registrations. Where Tika canonicalizes on a deprecated or private-tree name, the IANA type wins via canonicalize:

  • application/yaml over text/x-yaml (RFC 9512) — text/yaml, text/vnd.yaml, application/x-yaml, and the rest of the family all resolve to it; .yaml/.yml follow
  • application/vnd.debian.binary-package over application/x-debian-package (IANA lists the latter as the deprecated alias); .deb/.udeb follow
  • application/xliff+xml over application/x-xliff+xml (IANA-registered since 2018) — closes Support older XLIFF mime type (application/x-xliff+xml) #84 with both spellings resolving to the standard type
  • application/oxps is IANA-registered as its own format and not interoperable with Microsoft XPS. Severed at generation, not by runtime overlay: ALIAS_SKIPS drops Tika's alias, GLOB_REASSIGNMENTS moves the oxps glob to application/oxps (declared in data/custom.xml with its OPC parent), and the generator verifies the reassigned glob is claimed. Magic-only loading, forward lookup, reverse extension listings, and later re-extends of the Microsoft type all agree: .xps is Microsoft XPS, .oxps is OpenXPS

The remaining direction suspects (bat, matlab, aiff, xcf, java-properties, avi families) have no IANA registration on either side, so Tika's direction stands. The wav family keeps audio/x-wav by deliberate browser-reality choice, alongside audio/aac and audio/flac. Explicit regression tests pin every one of these calls.

MimeType.canonicalize(type, instead_of:)

Overrides a Tika canonical type with our own: the old type's extensions, magic matchers, parents, and aliases re-register under the new name, and the old name becomes an alias. Replaces the hand-copied matcher/extension/parent declarations for audio/aac, audio/flac, and audio/x-wav — the types browsers actually use — while keeping Tika's matchers, and fixes audio/x-wav's dangling audio/vnd.wav parent (the Tika type is audio/vnd.wave).

Runtime registration holds the generator's invariants, atomically

Magic.add normalizes and validates the complete registration — alias keys downcased, aliasing a registered type rejected with a pointer to canonicalize (the sanctioned path, which re-points existing aliases itself) — before mutating any table, so a rejected registration leaves every registry untouched, including previously-held extension ownership. Alias keys are never registered types, alias values are never alias keys, and resolution is single-hop by construction. MimeType.extend normalizes its type at the mutation boundary and redirects aliased types to their canonical with a warning, so registrations land where lookups resolve regardless of input case.

Redundancy warnings

MimeType.extend now takes aliases: and warns on redundant extends — re-declaring extensions, aliases, or parents the tables already carry. Running the warnings against our own definitions.rb flushed out declarations newer Tika data had absorbed (illustrator's pdf parent; iWork/avif/heif/heic/markdown extensions); those are pruned so Marcel loads warning-free.

There is deliberately no duplicate-magic warning: matcher order determines precedence, so re-registering an existing matcher legitimately promotes it ahead of the generated tables — exactly how avif/heif/heic outrank video/quicktime's broad ftyp match. (Found the hard way: pruning those "duplicates" regressed avif/heif to quicktime.)

Deliberate carve-outs

  • ALIAS_SKIPS at generation: application/x-x509-ca-cert stays a distinct type — Marcel reuses the name for PEM-format certificates under application/x-x509-cert;format=pem.
  • The generator rejects aliases that would shadow a defined type, so the tables can't disagree with themselves.
  • Parameterized aliases (image/vnd.dgn;ver=8) are modeled, but declared types parse down to bare type/subtype (Validate declared MIME types #160), so they resolve through their base type rather than the alias table.

Tests

596 runs (51 new over main), 0 failures; warning-free require "marcel"; tables:check green. New coverage: the IANA-direction regressions above, OpenXPS pinned at every layer (forward, reverse, magic-only tables, post-extend stability), a rejected registration proven to leave all five registries untouched by snapshot comparison, mixed-case extend redirection, canonicalize round-trip (extensions/magic/parents/aliases all follow the rename), alias removal semantics, child? through aliases on both sides, exhaustive declared-type alias resolution, and every name fixture re-asserted against each alias of its expected type.

@jeremy
jeremy force-pushed the respect-mime-type-aliases branch from 62a8fe3 to 1f46a9f Compare August 20, 2026 06:02
Model Tika's type aliases instead of discarding them. The generated
tables gain a TYPE_ALIASES map (152 aliases extracted from the <alias>
elements, downcased to match Marcel's lowercase-normalized lookups),
and alias resolution reaches every API:

* Declared types resolve to their canonical type, so a client-supplied
  application/javascript comes back text/javascript, audio/x-aac comes
  back audio/aac, and so on for the whole alias table.
* Magic.child? resolves aliases on both sides and through the parent
  graph, so parents declared via an alias (as Tika does for X bitmap's
  text/x-c) work without hand-maintained overrides — the custom.xml
  workaround pinning image/x-xbitmap to text/x-csrc is now unnecessary
  and removed, closing that file's standing TODO.
* Magic.canonical/by_type and Magic#canonical expose resolution
  directly. Class-level canonical is allocation-free for normalized
  input (measured: 0 allocations/call lowercase, and child? holds at
  its preexisting 2 — traversal array and visited hash) since child?
  resolves every node it visits.

Tika's alias direction is data, not policy: audited all 152 against
IANA registrations. Where Tika canonicalizes on a deprecated or
private-tree name, the IANA type wins via canonicalize:

* application/yaml over text/x-yaml (RFC 9512; the text/* and x-
  spellings all resolve to it)
* application/vnd.debian.binary-package over application/x-debian-
  package (IANA lists the latter as the deprecated alias)
* application/xliff+xml over application/x-xliff+xml (IANA-registered
  since 2018) — closes #84 with both spellings resolving to the
  standard type
* application/oxps is IANA-registered as its own format and not
  interoperable with Microsoft XPS. The severance is generation-level:
  ALIAS_SKIPS drops Tika's alias, GLOB_REASSIGNMENTS moves the oxps
  glob to application/oxps (declared in data/custom.xml with its OPC
  parent), and the generator verifies the reassigned glob is claimed.
  Magic-only loading, forward lookup, reverse extension listings, and
  later re-extends of the Microsoft type all agree: .xps is Microsoft
  XPS, .oxps is OpenXPS.

The remaining suspects (bat, matlab, aiff, xcf, java-properties, avi
families) have no IANA registration on either side; Tika's direction
stands. The wav family keeps audio/x-wav by deliberate browser-reality
choice, alongside audio/aac and audio/flac.

Introduce MimeType.canonicalize(type, instead_of:) to make those
overrides: the old type's extensions, magic matchers, parents, and
aliases re-register under the new name, and the old name becomes an
alias. This also replaces the hand-copied matcher/extension/parent
declarations for the audio types and fixes audio/x-wav's dangling
audio/vnd.wav parent (the Tika type is audio/vnd.wave).

Runtime registration holds the generator's invariants, atomically:
Magic.add normalizes and validates the complete registration — alias
keys downcased, aliasing a registered type rejected with a pointer to
canonicalize — before mutating any table, so a rejected registration
leaves every registry untouched. Alias keys are never registered
types, alias values never alias keys, and resolution is single-hop by
construction. MimeType.extend normalizes its type at the mutation
boundary and redirects aliased types to their canonical with a
warning, so registrations land where lookups resolve regardless of
input case.

MimeType.extend also gains aliases: and warns on redundant extends —
re-declaring extensions, aliases, or parents the tables already have.
Those warnings flushed out definitions that newer Tika data had
absorbed (illustrator parent, iWork/avif/heif/heic/markdown
extensions); they're pruned so Marcel loads warning-free. There is
deliberately no duplicate-magic warning: matcher order determines
precedence, so re-registering an existing matcher legitimately
promotes it ahead of the generated tables, which is exactly how
avif/heif/heic outrank video/quicktime's broad ftyp match.

ALIAS_SKIPS also retains application/x-x509-ca-cert as a distinct
type, reused as the PEM-format certificate type under
application/x-x509-cert;format=pem. The generator rejects aliases that
would shadow a defined type, so the tables can't disagree with
themselves.

Parameterized aliases (image/vnd.dgn;ver=8) are modeled, but declared
types parse down to bare type/subtype, so they resolve through their
base type rather than the alias table.

Supersedes and closes #101. Closes #84.
@jeremy
jeremy force-pushed the respect-mime-type-aliases branch from 1f46a9f to d3b7267 Compare August 20, 2026 06:53
@jeremy
jeremy merged commit 56e5402 into main Aug 20, 2026
20 checks passed
@jeremy
jeremy deleted the respect-mime-type-aliases branch August 20, 2026 07:46
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.

Support older XLIFF mime type (application/x-xliff+xml)

1 participant