Skip to content

fix: require "type/" prefix when matching MIME families in PreloadHTML#194

Merged
linkdata merged 2 commits into
mainfrom
fix/182-preload-mime-family-slash
Jul 21, 2026
Merged

fix: require "type/" prefix when matching MIME families in PreloadHTML#194
linkdata merged 2 commits into
mainfrom
fix/182-preload-mime-family-slash

Conversation

@linkdata

Copy link
Copy Markdown
Owner

Fixes #182.

Problem

assets.PreloadHTML classified MIME families with strings.HasPrefix(mimetype, "image") and "font" rather than the "image/" and "font/" prefixes, so unrelated types such as imagery/* and fontastic/* were mistaken for images or fonts. This let non-image resources be emitted as favicons and non-font resources receive font preload metadata. Matching was also case-sensitive, so validly-typed-but-differently-cased resources (IMAGE/*, FONT/*) were missed.

Fix

Match on the "image/" and "font/" prefixes, lowercasing the resolved MIME type first so family matching is case-insensitive. Only genuine image/* types now qualify as favicons, and only genuine font/* types receive as="font" preload handling.

Tests

Added Test_PreloadHTML_MIMEFamilyMatching, which registers imagery/*, fontastic/*, IMAGE/* and FONT/* extensions and asserts:

  • imagery/* is not treated as an image (no favicon, no as="image").
  • fontastic/* is not treated as a font (no as="font").
  • IMAGE/* is recognized as an image and its favicon-named resource wins the favicon slot.
  • FONT/* is recognized as a font and receives as="font".

The test fails against the unfixed source and passes with the fix. go vet and go test -race ./lib/assets/ are clean.

Acceptance criteria from the issue:

  • Only image/* types qualify as favicons.
  • Only font/* types receive font preload handling.
  • Family matching is case-insensitive.
  • Add regressions for false prefixes and existing image/font cases.

linkdata added 2 commits July 21, 2026 10:37
assets.PreloadHTML classified MIME families with HasPrefix(mimetype,
"image") and "font", so unrelated types such as "imagery/*" and
"fontastic/*" were treated as images or fonts. That let non-image
resources be emitted as favicons and non-font resources receive font
preload metadata. Matching was also case-sensitive, missing valid types
like "IMAGE/*" or "FONT/*".

Match on the "image/" and "font/" prefixes case-insensitively so only
genuine image/* types qualify as favicons and only genuine font/* types
receive font preload handling.
Test_PreloadHTML computed its expected font preload link with
strings.HasPrefix(fontMime, "font"), a case-sensitive check without the
trailing slash. Since PreloadHTML now matches "font/" case-insensitively,
a platform returning "FONT/woff2" would emit as="font" while the test
expected the bare preload form, failing spuriously. Mirror the production
classification so the expectation tracks the code on any MIME table.
@linkdata
linkdata merged commit 634f8c9 into main Jul 21, 2026
7 checks passed
@linkdata
linkdata deleted the fix/182-preload-mime-family-slash branch July 21, 2026 08: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.

PreloadHTML matches MIME prefixes without requiring a slash

1 participant