Skip to content

fix(html): rewrite CSS url() references to use hashed filenames - #3046

Open
jhult wants to merge 2 commits into
rust-lang:mainfrom
jhult:fix/css-url-rewriting
Open

jhult wants to merge 2 commits into
rust-lang:mainfrom
jhult:fix/css-url-rewriting

Conversation

@jhult

@jhult jhult commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

Fixes #2958

When font files are hashed for cache-busting, CSS url() references were not updated to use the hashed filenames, causing custom fonts to fail loading.

This fix rewrites url() references in CSS files during write_files, handling all three quoting styles (url("…"), url('…'), url(…)), resolving paths relative to the CSS file's location before looking up in the hash map, and leaving absolute/data URLs untouched.

@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label Mar 3, 2026
@jhult
jhult force-pushed the fix/css-url-rewriting branch from f71812a to cacc8f7 Compare March 16, 2026 19:25
@rustbot

This comment has been minimized.

@jhult
jhult force-pushed the fix/css-url-rewriting branch from cacc8f7 to e375fc4 Compare April 22, 2026 00:29
@rustbot

rustbot commented Apr 22, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@GuillaumeGomez

Copy link
Copy Markdown
Member

Sorry for the delay! We now have an mdbook team so review should hopefully be a bit faster. It's a big PR so I'll try to come back to it soon.

static_regex!(
CSS_URL,
bytes,
r#"url\(\s*(?:"([^"]*?)"|'([^']*?)'|([^'"\s()]+))\s*\)"#

@GuillaumeGomez GuillaumeGomez Sep 3, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using a regex, why not add in the CSS files something like:

property: /* hashed-url-file: original-filename */;

Like that we only need to look for /* hashed-url-file: and replace the given filename with its hashed version.

View changes since the review

@GuillaumeGomez GuillaumeGomez added S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. A-needs-discussion This issue/PR needs to be discussed by the team and removed S-waiting-on-review Status: waiting on a review labels Sep 14, 2026
@rustbot

rustbot commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (possibly #3222) made this pull request unmergeable. Please resolve the merge conflicts.

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

Labels

A-needs-discussion This issue/PR needs to be discussed by the team S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Local custom font files are serialized since version 0.5 - how to reference them?

3 participants