Skip to content

fix(wp): match local font file names to the sanitized upload name - #26

Merged
DavidBabinec merged 1 commit into
mainfrom
fix/local-font-filename-spaces
Aug 28, 2026
Merged

fix(wp): match local font file names to the sanitized upload name#26
DavidBabinec merged 1 commit into
mainfrom
fix/local-font-filename-spaces

Conversation

@DavidBabinec

Copy link
Copy Markdown
Contributor

Fixes #24

The bug

Local fonts whose family name has a space (for example Source Sans 3) never load on the front end. WordPress stores the upload under a sanitized name, where spaces become dashes, but the @font-face src was built from the raw family and kept the spaces. It pointed at a file that 404s, and the browser dropped the font silently. Reported by a customer on 2.0.1.

The fix

The upload file name and the CSS src now come from one helper, localFontFileName, which sanitizes the name the way sanitize_file_name() does, so the URL always matches the file on disk. Font deletion uses it too. The helper lives in core with unit coverage. The www app is unaffected: it references the real file URLs, not a constructed path. Existing broken fonts need one re-save to regenerate their CSS.

Verification

bun run test:www          # 156 pass, 0 fail (new sanitizeFontFileName suite)
bun run build:wp          # clean
bun run check:open-source # clean

Notes

The importer also downloads the same variable font once per weight (byte identical). Left as a follow-up.

@DavidBabinec
DavidBabinec merged commit 6bcfbc1 into main Aug 28, 2026
6 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.

[Bug]: Local fonts with a space in the family name 404 on the front end

1 participant