Repository navigation
Respect MIME type aliases - #171
Merged
Merged
Conversation
jeremy
force-pushed
the
respect-mime-type-aliases
branch
from
August 20, 2026 06:02
62a8fe3 to
1f46a9f
Compare
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
force-pushed
the
respect-mime-type-aliases
branch
from
August 20, 2026 06:53
1f46a9f to
d3b7267
Compare
This was referenced Aug 21, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #101 (2024's
aliasesbranch, 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_ALIASESmap — 152 aliases extracted from the data's<alias>elements, downcased to match Marcel's lowercase-normalized lookups — and alias resolution reaches every API: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'stext/x-c) work without hand-maintained overrides —custom.xml's workaround pinningimage/x-xbitmaptotext/x-csrcis removed, closing that file's standing TODO.Magic.canonical/Magic.by_type/Magic#canonicalexpose resolution directly. Class-levelcanonicalis allocation-free for normalized input — measured 0 allocations/call lowercase, withchild?holding at its preexisting 2 (traversal array + visited hash) — sincechild?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/yamlovertext/x-yaml(RFC 9512) —text/yaml,text/vnd.yaml,application/x-yaml, and the rest of the family all resolve to it;.yaml/.ymlfollowapplication/vnd.debian.binary-packageoverapplication/x-debian-package(IANA lists the latter as the deprecated alias);.deb/.udebfollowapplication/xliff+xmloverapplication/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 typeapplication/oxpsis IANA-registered as its own format and not interoperable with Microsoft XPS. Severed at generation, not by runtime overlay:ALIAS_SKIPSdrops Tika's alias,GLOB_REASSIGNMENTSmoves theoxpsglob toapplication/oxps(declared indata/custom.xmlwith 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:.xpsis Microsoft XPS,.oxpsis OpenXPSThe remaining direction suspects (
bat,matlab,aiff,xcf,java-properties,avifamilies) have no IANA registration on either side, so Tika's direction stands. Thewavfamily keepsaudio/x-wavby deliberate browser-reality choice, alongsideaudio/aacandaudio/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, andaudio/x-wav— the types browsers actually use — while keeping Tika's matchers, and fixesaudio/x-wav's danglingaudio/vnd.wavparent (the Tika type isaudio/vnd.wave).Runtime registration holds the generator's invariants, atomically
Magic.addnormalizes and validates the complete registration — alias keys downcased, aliasing a registered type rejected with a pointer tocanonicalize(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.extendnormalizes 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.extendnow takesaliases:and warns on redundant extends — re-declaring extensions, aliases, or parents the tables already carry. Running the warnings against our owndefinitions.rbflushed 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 broadftypmatch. (Found the hard way: pruning those "duplicates" regressed avif/heif to quicktime.)Deliberate carve-outs
ALIAS_SKIPSat generation:application/x-x509-ca-certstays a distinct type — Marcel reuses the name for PEM-format certificates underapplication/x-x509-cert;format=pem.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:checkgreen. 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.