Opened 17 months ago
Last modified 5 weeks ago
#63568 accepted defect (bug)
WP_Font_Face: Font names that contain single quotes are not wrapped in double quotes
| Reported by: | wildworks | Owned by: | audrasjb |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Editor | Version: | 6.4 |
| Severity: | normal | Keywords: | has-patch has-test-info has-screenshots has-unit-tests needs-testing dev-feedback |
| Cc: | Focuses: | ui, css |
Description
Originally reported in GB 70426.
The WP_Font_Face::build_font_face_css method checks the font name and wraps it in double quotes if it contains spaces. However, if the font name contains a single quote, it will be erroneously detected as already "wrapped" and the wrapping process will not be performed.
As a result, the correct CSS will not be generated, and the font will not be applied:
<style class='wp-fonts-local'>
@font-face{
font-family:O'Reilly Sans;
}
</style>
This code should be:
<style class='wp-fonts-local'>
@font-face{
font-family:"O'Reilly Sans";
}
</style>
On the other hand, CSS variable values are correctly wrapped in double quotes. This is because it is properly handled by the WP_Font_Utils::maybe_add_quotes method:
<style id='global-styles-inline-css'>
:root{
--wp--preset--font-family--oreilly-sans: "O'Reilly Sans"
}
</style>
The solution should probably be one of the following:
- Make the logic of the
build_font_face_cssmethod the same as themaybe_add_quotesmethod. - Deprecate the
build_font_face_cssmethod and use themaybe_add_quotesmethod instead.
Testing Instructions
- Open the site editor.
- Click on the Styles button in the top right.
- Typography > Fonts section > click the Manage fonts button
- Click the Upload tab
- Upload the
O-Reilly-Sans-Regular.ttffont file attached to this ticket. This font is Savate font, an open-licensed font published on Google Fonts, and I changed the font name to "O'Reilly Sans" using FontForge. - Close the font modal.
- Elements section > Text > Typography section
- Select the "O'Reilly Sans" font from the Font dropdown.
- The font will be applied throughout the site editor, most likely because the font is being loaded in JS and not via PHP.
- Click the save button and reload your browser. The font should no longer be applied.
- The font should no longer be applied on the front end.
Attachments (3)
Change History (67)
#1
@
17 months ago
- Keywords needs-patch added
- Milestone Awaiting Review → 6.9
- Owner set to
- Status new → accepted
- Version → 6.4
Thanks for the Trac report, I'm able to reproduce the issue using the provided font.
Introduced in [56012] / WP 6.4.
I moved this to milestone 6.9 but I wouldn't be opposed to ship it in the next report, depending on how self-contained and straightforward is the proposed patch.
This ticket was mentioned in PR #8982 on WordPress/wordpress-develop by @sandeepdahiya.
17 months ago
#2
- Keywords has-patch added; needs-patch removed
I have created a patch for the following Trac ticket:
Trac ticket: https://core.trac.wordpress.org/ticket/63568
Details for the bug reproduction can be found here.
In this patch, the quotes are added by using the logic of maybe_add_quotes method in the build_font_face_css function.
The comparison of input and output before the patch and after the patch is:
Here is the before patch (bug reproduction video):-
https://github.com/user-attachments/assets/d93736c0-d410-46da-84fa-38900f843471
After patch (test report video):-
https://github.com/user-attachments/assets/4a610657-5c09-4de1-92a2-f161c9910812
@wildworks commented on PR #8982:
17 months ago
#3
Thanks for the PR!
I'm thinking it might be better to expose the maybe_add_quotes method rather than duplicating it. Because the method belongs to a utility class.
That way, it should be available in the form of WP_Font_Utils::maybe_add_quotes().
@sandeepdahiya commented on PR #8982:
17 months ago
#4
I'm thinking it might be better to expose the
maybe_add_quotesmethod rather than duplicating it. Because the method belongs to a utility class.
To me, this seems better choice as well without duplication/repeatations.
@wildworks commented on PR #8982:
17 months ago
#5
Thanks for the update! I think we can commit this PR once the PHP lint errors are fixed.
@jonsurrell commented on PR #8982:
17 months ago
#6
It seems good to always process the provided font family name, however I wonder whether we should improve on maybe_add_quotes to something like normalize_quoted_font_family_name.
I believe there are a number of edge cases that are unhandled here. Most of these are edge cases and not likely to appear in popular font names, however it seems ideal if the system behaves well under any conditions. For example, what happens if the string contains " instead of '?
This section of the CSS standard is interesting and relevant, in particular the notes:
means most punctuation characters and digits at the start of each token must be escaped in unquoted font family names.
if you really have a font whose name is the same as one of the <generic-family> names, or the system font names, or the CSS-wide keywords, it must be quoted.
I'd like to consider always using the quoted form of the font family name. This way they are handeled as CSS strings, and handling a few characters should ensure that font names are correctly represented in the resulting CSS.
A quoted form of the name seems ideal where some escaping inside the quoted CSS string would be necessary, namely:
- Change
\to\\ - Change the quote character to its escaped form, so if
"is the quote used then"inside the string becomes\". - Newlines should become
\A.
---
I'm not familiar with the fonts API so this may be problematic in some ways I'm unaware of, but from the CSS perspective this should be more robust.
@jonsurrell commented on PR #8982:
17 months ago
#7
My comment is not intended to block this PR which seems to be an incremental improvement.
@wildworks commented on PR #8982:
17 months ago
#8
@sirreal Thanks for the feedback!
It seems good to always process the provided font family name, however I wonder whether we should improve on
maybe_add_quotesto something likenormalize_quoted_font_family_name.
I think this is a nice suggestion. This method was previously private, it should be safe to change the method name.
I believe there are a number of edge cases that are unhandled here.
This is true. There are also no unit tests and they will need to be added, but I think those can be addressed in a follow-up.
@sandeepdahiya commented on PR #8982:
17 months ago
#9
I believe there are a number of edge cases that are unhandled here. Most of these are edge cases and not likely to appear in popular font names, however it seems ideal if the system behaves well under any conditions. For example, what happens if the string contains
"instead of'?
Yes, there’s zero downside to being more defensive here.
I think this is a nice suggestion. This method was previously private, it should be safe to change the method name.
I agree, this is a good suggestion. I've gone ahead and added some edge cases as mentioned above by @sirreal and renamed the method to normalize_quoted_font_family_name since it better reflects what the function is doing now.
@wildworks commented on PR #8982:
17 months ago
#10
@iamsandeepdahiya Thanks for the update. If we change the logic of the method itself, I feel like we need unit testing to prevent regressions. This method is very hard to test manually.
@wildworks commented on PR #8982:
17 months ago
#11
My recommendation would be to land the simpler fix and then create a new PR with the additional improvements.
I agree with this suggestion. I think it would be better to make only minimal changes here and address the logic changes and adding unit tests in a follow-up.
The feedback left by @sirreal will be useful when creating a follow-up PR. Looking at the feedback, it seems that there are many edge cases that need to be tested carefully 😅
@sandeepdahiya commented on PR #8982:
17 months ago
#12
I agree with this suggestion. I think it would be better to make only minimal changes here and address the logic changes and adding unit tests in a follow-up.
I have reverted the last commit as discussed and the recent changes have been undone. The branch is now back to the previous state. Please let me know if any further adjustments are needed. ✅
#14
@
17 months ago
- Focuses ui added
- Keywords has-test-info has-screenshots added
Test Report
Description
This report validates whether the indicated patch works as expected.
Patch tested: https://github.com/WordPress/wordpress-develop/pull/8982
Environment
- WordPress: 6.9-alpha-60093-src
- PHP: 8.2.28
- Server: nginx/1.27.5
- Database: mysqli (Server: 8.4.5 / Client: mysqlnd 8.2.28)
- Browser: Chrome 136.0.0.0
- OS: Linux
- Theme: Twenty Twenty-Five 1.2
- MU Plugins: None activated
- Plugins:
- Test Reports 1.2.0
Actual Results
- ✅ Issue resolved with patch.
- Custom font named "O'Reilly Sans" is now correctly wrapped in double quotes in the generated @font-face CSS:
- The font remains applied after refreshing the Site Editor and is correctly rendered on the frontend.
Additional Notes
- With the patch applied, the quoting issue is fixed, resulting in valid CSS output.
Supplemental Artifacts
Video recording: https://www.awesomescreenshot.com/video/41086843?key=c613daad2490e76793493416500628f5
#15
@
17 months ago
Leaving the needs-testng keywords for more testing from other contributors, not sure if we need unit-test though. I'll leave that open for discussions
@jonsurrell commented on PR #8982:
17 months ago
#17
Please don't wait for additional review from me, I'm not familiar with the font system and am satisfied with @t-hamano's approval.
#19
@
17 months ago
- Keywords reporter-feedback added; needs-testing removed
Reproduction Report
Description
❌ This report can't validate that the issue can be reproduced.
Environment
- WordPress: 6.9-alpha-60093-src
- PHP: 7.4.33
- Server: nginx/1.27.5
- Database: mysqli (Server: 8.4.5 / Client: mysqlnd 7.4.33)
- Browser: Firefox 139.0
- OS: Windows 10/11
- Theme: Twenty Twenty-Five 1.2
- MU Plugins: None activated
- Plugins:
- Test Reports 1.2.0
Reproduction Steps
- Following the ones provided in the OP
Actual Results
- ❌ Error conditions is not occurring, check screencast
Additional Notes
@wildworks it seems that there has been some validation already, but I can't seem to validate this, following your steps. Can you check my screencast and give me some feedback on what I'm missing? Maybe an environment difference?
Supplemental Artifacts
Screencast. https://f003.backblazeb2.com/file/wordpress-videos/wp-videos/2025/06/63568.mp4
#20
follow-up:
↓ 21
@
17 months ago
@SirLouen Thanks for the testing.
After further testing, I found this test to be very unstable.
My guess is that this is an issue, possibly with file uploads.
After following the steps I have shown you, check the source code on the frontend - the font family itself should be defined correctly.
<style class='wp-fonts-local'>
<!-- Some other fonts definisions -->
@font-face{font-family:"O'Reilly Sans";font-style:normal;font-weight:400;font-display:fallback;src:url('http://localhost:8889/wp-content/uploads/fonts/O-Reilly-Sans-Regular.ttf') format('truetype');}
</style>
Try accessing http://localhost:8889/wp-content/uploads/fonts/O-Reilly-Sans-Regular.ttf, which is indicated by this definition. In my environment, for some reason, the font could not be found.
I used the Font Manager plugin to monitor whether the font file was actually uploaded. Strangely, the uploaded font may disappear immediately. See the video below:
https://i.gyazo.com/a10898228bc4290f0b77442a5449de7e.mp4
Here is what I discovered:
- This problem does not occur with common font files that do not contain single quotes.
- After repeatedly deleting and updating the font, the font becomes available for upload.
- This problem also occurs in trunk.
In conclusion, I think this behavior is either a niche bug related to the font file upload process that has existed in trunk, or there is some mistake in the font I prepared.
Either way, this patch does not change anything in the font file upload process, so I think it is safe.
#21
in reply to: ↑ 20
@
17 months ago
Replying to wildworks:
Try accessing http://localhost:8889/wp-content/uploads/fonts/O-Reilly-Sans-Regular.ttf, which is indicated by this definition. In my environment, for some reason, the font could not be found.
I've tried this, but I can find the font
https://f003.backblazeb2.com/file/wordpress-videos/wp-videos/2025/06/63568-2.mp4
It's so weird how the font disappears from your disk. I've also tried the same protocol
https://f003.backblazeb2.com/file/wordpress-videos/wp-videos/2025/06/63568-3.mp4
But it doesnt dissapear from my disk.
Btw? Have you tried reproducing with WP Playground? We cannot access the filesystem but you can see visually the result if its expected or not.
#22
follow-up:
↓ 23
@
17 months ago
@SirLouen
Thanks for the test. The disappearance of the font file may be a problem with my environment.
I tested it again using Playground, but I was unable to reproduce the problem you are encountering. I used the following two browsers:
- Chrome 137.0.7151.119
- Firefox 139.0.4
On the front end, could you make sure the following code is present in your source? If they are all present after running the test steps correctly, the font should be applied correctly.
<style class='wp-fonts-local'>
@font-face{
font-family:"O'Reilly Sans";
font-style:normal;
font-weight:400;
font-display:fallback;
src:url('/path/to/wp-content/uploads/fonts/O-Reilly-Sans-Regular.ttf') format('truetype');
}
</style>
<style id='global-styles-inline-css'>
:root{
--wp--preset--font-family--oreilly-sans: "O'Reilly Sans";
}
body{
font-family: var(--wp--preset--font-family--oreilly-sans);
}
</style>
#23
in reply to: ↑ 22
;
follow-up:
↓ 24
@
17 months ago
Replying to wildworks:
Thanks for the test. The disappearance of the font file may be a problem with my environment.
What is your environment, exactly? Are you running npm run dev, with the file watcher?
I've noticed before that npm run dev will sometimes (not always and not very reproducibly, but sometimes) delete uploaded files.
#24
in reply to: ↑ 23
;
follow-up:
↓ 25
@
17 months ago
Replying to siliconforks:
Are you running
npm run dev, with the file watcher?
That's right. I've tried it in various environments, but the problem seems to occur when running the wordpress-develop repository by running npm run dev. This issue may need to be investigated in more depth in a separate ticket.
#26
in reply to: ↑ 25
;
follow-up:
↓ 27
@
17 months ago
What I don't really get is how this patch is going to solve #63605
After all the font disappears after uploading. It won't be never loaded regardless of the code changes.
I feel that the code is addressing another problem with another reproduction instructions right?
These instructions?
#27
in reply to: ↑ 26
;
follow-up:
↓ 28
@
17 months ago
Replying to SirLouen:
This patch (This PR) does not solve #63605. The problem of disappearing font files is not related to this patch. This patch just wraps the font family name with proper double quotes so that the font-face is generated correctly.
However, it is true that disappearing font files make it difficult to test this patch accurately.
#28
in reply to: ↑ 27
;
follow-up:
↓ 29
@
17 months ago
Replying to wildworks:
However, it is true that disappearing font files make it difficult to test this patch accurately.
I believe npm run build:dev is the same thing as npm run dev but without running the file watcher? So it should be possible to use that as a workaround to avoid running into #63605.
There's also npm run build which gives you a production build (in the build/ directory) instead of a development build (again without running the file watcher).
#29
in reply to: ↑ 28
@
17 months ago
- Keywords reporter-feedback removed
Test Report
Description
✅ This report validates that the indicated patch works as expected.
Patch tested: https://github.com/WordPress/wordpress-develop/pull/8982.diff
Environment
- WordPress: 6.9-alpha-60093-src
- PHP: 8.2.28
- Server: nginx/1.27.5
- Database: mysqli (Server: 8.4.5 / Client: mysqlnd 8.2.28)
- Browser: Chrome 137.0.0.0
- OS: Windows 10/11
- Theme: Twenty Twenty-Five 1.2
- MU Plugins: None activated
- Plugins:
- Test Reports 1.2.0
Testing Instructions
- Loading the font proposed here, as commented in OP instructions
- Set the font as default Text font
- Go to the front end and check the code. Look for the name of the font. In this case, "Reilly Sans". You might spot it in two places: in the local fonts, and in the CSS vars (check supplemental artifacts)
- The CSS var is correctly set with double quotes
- 🐞 The local font lacks of the double quotes
Expected Results
- Ideally, the local fonts should also display the font within double quotes
Actual Results
- ✅ With the patch the font is displayed with double quotes, check supplemental artifacts.
Additional Notes
Replying to siliconforks:
Replying to wildworks:
However, it is true that disappearing font files make it difficult to test this patch accurately.
I believe
npm run build:devis the same thing asnpm run devbut without running the file watcher? So it should be possible to use that as a workaround to avoid running into #63605.
There's also
npm run buildwhich gives you a production build (in thebuild/directory) instead of a development build (again without running the file watcher).
Let me recap
The problem here is that originally, the font was not being shown to @wildworks. This was because the font was disappearing and not correctly set with double quotes, 50/50.
Then I checked the bug, and it was working for me (I always run npm run build:dev because I rarely work with JS files live), so the font was showing for me for some reason.
But now I see that with the patch, the font displays consistently both in the front end and in the back end (when it's not deleted!). This was my confusion. And as @wildworks suggested, this patch adds a degree of correctness.
✅ So I think that this patch is safe to ship
Supplemental Artifacts
Global Styles
Fonts Local Before patch
Fonts Local After patch
#31
@
14 months ago
@wildworks Are you able to upload an open-source font modified with FontForge to contain a double quote in the name? I tried to figure out how to do it myself but without success, I'm afraid.
@peterwilsoncc commented on PR #8982:
14 months ago
#32
@iamsandeepdahiya Are you able to add some tests using the modified font file on the ticket that contains a single quote?
@
14 months ago
Savate font, but the font name has been changed to O"Reilly Sans using FontForge (contains double quotes)
@
14 months ago
"O-Reilly-Sans-Regular-double-quotes-included.ttf" file information. The font name contains double quotes.
#33
@
14 months ago
Thanks @wildworks.
A font with double quotes in the name will fail during upload due to a JavaScript error, so I am unclear if the use case is resolved. However the use case isn't included in the font family test suite on the spec so I am not overly concerned.
#34
@
14 months ago
A font with double quotes in the name will fail during upload due to a JavaScript error
I was able to upload a font with double quotes in the site editor, but the @font-face definition inculudes unescaped double quotes:
@font-face {
font-family: O"Reilly Sans;
font-style: normal;
font-weight: 400;
font-display: fallback;
src: url('http://localhost:8888/wp-content/uploads/fonts/O-Reilly-Sans-Regular-double-quotes-included.ttf') format('truetype');
}
As a result, most of the global styles inline CSS will break and no styles will be applied to the site.
I don't have a strong opinion whether we should address this problem in PR 8982. As a follow-up, we can also improve the normalize_css_font_family_name method to escape double quotes.
#35
@
14 months ago
I started to work on improvements to the proposed normalization function and have some findings to share. I'm unfamiliar with the font system in WordPress, so I may have misinterpreted or overlooked some things. In particular, I'm not familiar with the system as a whole and am mostly interpreting things from the CSS perspective.
The linked PR touches font families in two places:
I believe these serve different purposes while both dealing with font-family. This is because ::build_font_face_css() corresponds to an @font-face at-rule. This @font-family font-family takes a single value. It is not the same as the font-family CSS property that takes a comma-separated list of values to match font-family.
On the linked PR, I suggested always quoting font names. That must not be applied in both places. I believe it should be applied in ::build_font_face_css() but not ::sanitize_font_family().
The main problem being addressed here is in WP_Font_Face::build_font_face_css() where a simple font family string is provided (as part of a larger $font_face array). This is a PHP string of a font family name, not a CSS string.
Assuming the input is a PHP string (not an escaped or quoted CSS string) the provided font-family name can and should be normalized. Always quoting the value simplifies escaping and prevents collisions with generic family names. See the specification.
Normalization might look something like this:
<?php function normalize_font_family_name( string $font_family ): string { return '"' . strtr( trim( $font_family, " \t\r\f\n"), array( /* * Normalize preprocessed whitespace. * https://www.w3.org/TR/css-syntax-3/#input-preprocessing */ "\r" => '\\A ', "\f" => '\\A ', "\r\n" => '\\A ', /* * CSS unicode escaping for problematic characters. * https://www.w3.org/TR/css-syntax-3/#escaping */ "\n" => '\\A ', '\\' => '\\5C ', ',' => '\\2C ', '"' => '\\22 ', ) ) . '"'; }
The linked PR also touches WP_Font_Utils::sanitize_font_family(). This function takes a string that is a CSS font-family declaration value. I recommended leaving this entire class untouched in the PR. Handling a single @font-face font family name and a font-family declaration value have different considerations and should not be conflated.
It splits a font-family description at ,, applies some functions (including normalization) to the parts, then joins the parts again with , .
The applied functions are sanitize_text_field (which is filterable) and possibly ::maybe_add_quotes() renamed to ::normalize_css_font_family_name() in the linked PR.
The sanitization function works on some expected inputs but will break some other valid inputs. Unfortunately, without some basic CSS parsing it's difficult to improve. Notably, the , character could be part of the CSS font name, in which case the sanitization will mangle the intended result. I doubt that most common font-family names use , in the name because it complicates use in CSS, so maybe we can ignore this point for now.
Quoting in this sanitization function cannot be done indiscriminately. Quotes must not be applied to generic font family names like sans-serif or they will not be treated as generic families.
This function is problematic in edge cases, but I think it's best left alone until we're prepared to implement some improved parsing. HTML API: Add CSS selector support #7857 may be helpful if folks are interested.
@jonsurrell commented on PR #8982:
14 months ago
#36
I've started work suggested changes in https://github.com/WordPress/wordpress-develop/pull/9951.
This ticket was mentioned in PR #9951 on WordPress/wordpress-develop by @jonsurrell.
14 months ago
#37
- Keywords has-unit-tests added
This includes tests to verify correct and expected behavior. It's not as straightforward to verify that the normalized font works correctly in the browser.
I've prepared a demonstration available test and compare how these encodings work. It includes some examples from the test suite and can be used to verify that, for example, these font families match:
@font-face { font-family:"BS\\Quot\"Apos'Semi;Comma,Newline\ALT<Oh😵My!"; } * { font-family: "BS\5C Quot\22 Apos\'Semi;Comma\2C Newline\A LT\3C Oh😵My!"; }
The behavior can be tested for regressions with the playground. The default twentytwentyfive theme will use the font families Manrope and Fira Code that can be tested on the playground.
Before (unquoted): https://playground.wordpress.net/?wp=6.8
After (quoted): https://playground.wordpress.net/?core-pr=9951
-@font-face{font-family:Manrope;font-style:normal;font-weight:200 800;font-display:fallback;src:url('h/wp-content/themes/twentytwentyfive/assets/fonts/manrope/Manrope-VariableFont_wght.woff2') format('woff2');} +@font-face{font-family:"Manrope";font-style:normal;font-weight:200 800;font-display:fallback;src:url('/wp-content/themes/twentytwentyfive/assets/fonts/manrope/Manrope-VariableFont_wght.woff2') format('woff2');} @font-face{font-family:"Fira Code";font-style:normal;font-weight:300 700;font-display:fallback;src:url('/wp-content/themes/twentytwentyfive/assets/fonts/fira-code/FiraCode-VariableFont_wght.woff2') format('woff2');}
Trac ticket: https://core.trac.wordpress.org/ticket/63568
#38
@
14 months ago
- Keywords needs-testing dev-feedback added; commit removed
I'd love to get review from someone more familiar with the font system on PR 9951. Testing would also be welcome.
@jonsurrell commented on PR #9951:
14 months ago
#39
I'd love to get feedback from folks that worked on Font Face CSS support. Based on history, @hellofromtonya and @oandregal may be candidates.
This ticket was mentioned in Slack in #core-test by jon_bossenger. View the logs.
12 months ago
#41
@
12 months ago
PR 9951 is a patch to address this. It's ready for review, but I'm not sure it's a candidate for 6.9 at this point in the release cycle.
#42
@
12 months ago
I apologize for the late reply. I don't have much bandwidth available, but I'll try my best to review the PR9951 this week.
I'd also like to send a message to @dmsnell about this matter. That's because he has a deep understanding of these kinds of problems.
To summarize this ticket, the goal is to properly escape the characters included in the font family name using the new normalize_css_font_family() function and enclose them in double quotes.
Actual:
<style class='wp-fonts-local'>
@font-face{
font-family: O'Reilly Sans;
}
</style>
Expected:
<style class='wp-fonts-local'>
@font-face{
font-family: "O'Reilly Sans";
}
</style>
#43
@
12 months ago
Thanks @wildworks for the ping. I will try and follow-up with this within a few days, but in the meantime I fully trust what @jonsurrell has to say on the matter. He’s even more knowledgeable on these mixed-environment scenarios.
It does seem like the issue isn’t so much that font names with an apostrophe cause problems, but rather that somewhere we have overlooked the fact that CSS strings may need to be quoted and escaped, and I like the direction he’s proposing to handle the generation of CSS strings given a raw PHP input value.
In #9299 I was working along a similar idea with $wpdb to properly escape “schema name identifiers” (table names, column names, etc…) and reject outright those which are truly invalid according to MySQL. There could be invalid or unrepresentable font names, and sometimes it’s best to put that understanding into the code, which also has the benefit of being able to reliably skip quoting when unnecessary.
@jonsurrell commented on PR #9951:
12 months ago
#44
I've been doing some testing and I have concerns about this approach. This has focused on fonts registered via theme.json, however after reviewing the issue and testing I've realized that font uploads are not processed by the functions that this PR touches.
I need to investigate how font uploads are processed. I've tested uploading a font named O"Reilly,Sans and it breaks the styling because of the quote wrapping. I'd expect that to work in this PR if set in a theme.json file, but it is not handled correctly as an uploaded font.
That case is interesting because we know it's a plain font name (not CSS) so there's no question of whether or not the value has been quoted or escaped already (see https://github.com/WordPress/wordpress-develop/pull/9951#discussion_r2491124999).
#45
@
12 months ago
I agree with the approach of keeping this fix minimal for now and handling broader normalization/escaping logic in a follow-up PR (as suggested earlier).
It might also be helpful to add a dedicated unit test for the normalize_quoted_font_family_name() method in the next iteration, to prevent regressions for edge cases like escaped quotes.
This ticket was mentioned in Slack in #core-test by krupajnanda. View the logs.
12 months ago
#47
@
12 months ago
Given that we're only a few days away from RC1, could we get a quick final review? Since it affects how font names are escaped and output in CSS, it would be safer to validate all edge cases before committing.
If we're unable to complete testing and review in the next day or two, I'd recommend punting this to the 7.0 milestone so we have enough time to add test coverage and confirm there are no regressions.
#48
@
12 months ago
- Milestone 6.9 → 7.0
Let's punt this to 7.0.
As far as I know, fonts with single quotes in their names are very rare, and problems only occur in a limited number of environments, so I don't think this is essential for the 6.9 release. Also, as mentioned here, we need to investigate the font upload logic as well.
This ticket was mentioned in Slack in #core by audrasjb. View the logs.
9 months ago
#50
@
9 months ago
- Milestone 7.0 → Future Release
As per today's 7.0 bug scrub:
The last comment during cycle 6.9 said "fonts with single quotes in their names are very rare, and problems only occur in a limited number of environments. […] we need to investigate the font upload logic as well".
Given this ticket didn't move a bit since then, I'm going to put this in Future Release milestone.
#51
@
8 months ago
- Focuses css added
There is conversation in the linked PR that's worth considering here. Some of the discussion initiated on lines of code and is not copied into this thread.
On the surface, this may seem like a simple issue. However, it raises a lot of questions. This type of problem arises from dealing working with CSS with no interface for parsing or manipulation. There are many parallels with HTML and the HTML API. Every day I see more motivation to introduce a CSS API.
Some observations from my investigation on this ticket:
- Uploading a font with an apostrophe in its like
O'Reilly Sansresults in broken CSS like the declarationfont-family: O'Reilly Sans;. There are many ways to fix this declaration, the simplest and most common is to quotefont-family: "O'Reilly Sans"; - The font name could contain virtually any text as long as it is quoted and or escaped correctly.
- WordPress has a mechanism that attempts to quote font families.
- WordPress also attempts to sanitize font-family values and maybe quote them.
- Surrounding a value in
"or'covers some cases but is insufficient. Values can contain'and or". - Splitting a comma-delimited list of values on
,is also insufficient.,can appear inside values in the list. - There are several
font-familyin CSS:- In
@font-facerules to specify the font family for the font. This takes a single value. - As a style property, which takes a comma-delimited list of values.
- I just learned it's also a descriptor of @font-pallete-values.
- In
font-familyvalues can be identifiers or strings (quoted values). Most font-family values can be represented in either way. One exception are generic fonts which must use the unquoted identifier form. String values can be used with the same font-family name as a generic, where the value type will differentiate.- Storing pieces of CSS in JSON is confusing and error-prone, especially when humans are authoring the JSON. For example:
- twentytwentyfive uses
{ "fontFamily": "\"Fira Code\"" }. This appears to be correct. The quoted CSS string"Fira Code"is encoded as the JSON string"\"Fira Code\"". - twentytwentythree uses
{ "fontFamily": "DM Sans" }(invalid valueDM Sansafter JSON decoding) but also uses{ "fontFamily": "\"DM Sans\", sans-serif" }(valid font-family value"DM Sans", sans-serifafter decoding).
- twentytwentyfive uses
- The typography documentation is unclear about expectations:
- "fontFamily: (Required) A valid value that will map to the CSS font-family value. Generally, this will be a font stack (a list of families that the browser will try to use in order)."
- "fontFamily: A valid CSS font-family descriptor."
- One example uses
"fontFamily": "'Open Sans', sans-serif", while another is"fontFamily": "Open Sans". I'd expect the latter to be"fontFamily": "'Open Sans'", `"fontFamily": "\"Open Sans\"", or similar.
- It's very difficult to try to normalize, correct, fix, or sanitize snippets of CSS values that are not ready to use when JSON decoded. The existing quoting and sanitization behavior complicates things further because efforts to correct the system likely need to maintain some of the behavior to avoid introducing regressions.
How does this move forward?
I'd like for this work to start by clarifying what the values in JSON actually are. If they're JSON-encoded CSS values, then the examples and Core themes should be updated accordingly, for example Open Sans should always be quoted.
The sanitization that splits on ,, maybe quotes, and joins needs to be re-evaluated. It may not be necessary at all or may do more harm than good.
It should not be necessary to strip tags from CSS. Since [61418], <style> tags should be "safe" with regards to HTML.
This ticket was mentioned in PR #11193 on WordPress/wordpress-develop by @jonsurrell.
8 months ago
#52
@jonsurrell commented on PR #11193:
8 months ago
#53
Alternative to https://github.com/WordPress/wordpress-develop/pull/9951
#54
@
8 months ago
PR 11193 fixes just the font upload in my testing.
It takes the fontFamily sent in the REST API and transforms it into a CSS string with CSS Unicode escapes for problematic characters. The REST API description for fontFamily is "CSS font-family value." It does not seem like that's the actual behavior, certainly the Gutenberg client is not sending a CSS value in many circumstances. Perhaps "CSS" was used to indicate that it's for the CSS property and not that it's a string of CSS source. The PR will clarify the description that it should be a plain string.
This seems like appropriate behavior.
This fix only focuses on font uploads like are described in this ticket. This fix should be resilient to things like the ,-split-and-sanitize behavior. Other questions about the font system are not considered.
I attempted to send an actual, escaped CSS string in the REST request in https://github.com/WordPress/gutenberg/pull/76253, but the value is then used in UI which results in escaped CSS strings appearing in dropdowns.
@jonsurrell commented on PR #11193:
8 months ago
#55
This doesn't seem to be an appropriate approach. I've tested the "install font" flow (that relies on Google Fonts) and that does send CSS strings like {"fontFamily":"\"B612 Mono\", monospace" }.
It does seem like:
- On upload, the client should be sending a CSS string, like in https://github.com/WordPress/gutenberg/pull/76253.
- The UI bugs that manifest in https://github.com/WordPress/gutenberg/pull/76253 should be addressed.
#56
@
8 months ago
There is an error in my previous comment:
invalid value
DM Sansafter JSON decoding
This is not accurate. DM Sans is valid and equivalent to "DM Sans". A font family name may be a quoted string or a sequence of one or more identifiers, in which case:
If a sequence of identifiers is given as a
<family-name>, the computed value is the name converted to a string by joining all the identifiers in the sequence by single spaces.
The spec does say:
To avoid mistakes in escaping, it is recommended to quote font family names that contain white space, digits, or punctuation characters other than hyphens
I don't see any reason not to quote all family names and only leave generics unquoted for the sake of simplicity in the font system. Custom idents cannot start with a number, so using quotes would protect against problems with a family name starting with a number.
#57
@
8 months ago
I've created GB PR 76782 which should completely fix this issue.
While this issue is fixed, a number of problems with fonts remain and there may be follow-up work. Several of the sanitization functions applied on to different font values could create problems with some font names.
The PR I've shared above is aware of most of the problems and avoids them by using CSS strings with Unicode escape sequences to replace a number of characters that are likely to be problematic.
@jonsurrell commented on PR #11193:
7 months ago
#58
https://github.com/WordPress/gutenberg/pull/76782 should fix the font upload issue.
@jonsurrell commented on PR #9951:
7 months ago
#59
https://github.com/WordPress/gutenberg/pull/76782 is an updated fix for the font upload issue.
I would like to return to some of the CSS sanitization functions and address them with a CSS tokenizer/processor.
This ticket was mentioned in PR #13610 on WordPress/wordpress-develop by @mmaattiiaass.
7 weeks ago
#60
What
Core applies text operations to CSS font-family values. Those operations change a font name or make invalid CSS. This PR replaces them with a shared CSS parser and serializer, so that a font name keeps its identity through validation, storage, resolution, and output.
The defect
The ticket reports that a font named O'Reilly Sans produces this declaration:
@font-face{font-family:O'Reilly Sans;}
WP_Font_Face::build_font_face_css() adds quotes only when the value holds a space and holds no quote character. The apostrophe reads as a quote, so the value stays unquoted. The declaration is invalid, and the browser does not use the font.
The same value path holds more defects. Each row is a CSS font-family value and the result from the current core functions:
| Input CSS value | Current result |
|---|---|
"ACME, Sans", sans-serif | Core splits the quoted name and returns "ACME", "Sans", sans-serif.
|
"Tom \26 Jerry" | sanitize_text_field() removes one space. The escape then consumes the space before Jerry.
|
"Font 50%AB" | sanitize_text_field() removes %AB.
|
"A B" | sanitize_text_field() changes two spaces to one space.
|
"A<B>" | sanitize_text_field() strips the text as markup.
|
ACME\,Sans, serif | Core splits at the escaped comma and returns invalid CSS. |
O"Reilly Sans | Core returns "O"Reilly Sans", which breaks the complete global styles stylesheet.
|
safecss_filter_attr() also splits declarations at every semicolon, so it rejects a valid name such as "A;B", and it rejects font-family:"Tom & Jerry".
How
New class WP_CSS_Font_Family (src/wp-includes/fonts/class-wp-css-font-family.php).
parse_list()reads the CSSfont-familygrammar and returns one entry per family. Each entry has atype(name,generic, orkeyword) and a decodedvalue. It handles quoted strings, identifier sequences, simple and hexadecimal escapes, comments, and thegeneric()function. It consumes the complete value and rejects extra tokens.parse_list_with_plain_names()adds a narrow compatibility path for an established plain name such asO'Reilly Sans. The path rejects a part that holds CSS syntax, for example;,{,(, or<.parse_descriptor_name()returns the single name for an@font-facedescriptor.serialize_name()writes a decoded name as a quoted CSS string.serialize_list()writes a list, and keeps each generic family as a keyword.
The parser is a single linear pass over the input. It uses no recursion and no backtracking regular expression. wp-settings.php loads the class before kses.php, so KSES can always call it.
Callers.
| File | Change |
|---|---|
class-wp-font-utils.php | sanitize_font_family() replaces sanitize_text_field(), explode( ',' ), and quote trimming. get_font_face_slug() compares decoded names.
|
class-wp-font-face-resolver.php | Selects the first family from the parsed entries instead of explode( ',' )[0].
|
class-wp-font-face.php | Reads the descriptor, then writes it as a quoted CSS string. An invalid value produces _doing_it_wrong() and the face is skipped.
|
class-wp-font-collection.php | The nested fontFace.fontFamily value uses the font family sanitizer instead of sanitize_text_field().
|
| Both font REST controllers | A fontFamily value that is not valid CSS and not a plain font name returns a 400 error.
|
kses.php | New _wp_kses_split_css_declarations() splits declarations with quote, parenthesis, and escape awareness. safecss_filter_attr() validates font-family with the font family grammar.
|
Compatibility decisions
A named family is always quoted; a generic family stays a keyword. This changes the canonical bytes of stored values and generated CSS:
-@font-face{font-family:Inter; ... } +@font-face{font-family:"Inter"; ... } -Arial, "Rock 3D", "Open Sans", serif +"Arial", "Rock 3D", "Open Sans", serif
Quoting is required for a name that starts with a digit, for a name that matches a generic keyword, and for a name that holds punctuation. One rule for every name removes the guessing. serif and "serif" stay distinct: the first is a generic family, the second is a font name.
The serializer escapes <, >, and & as CSS escapes. < and > cannot close a style element. & cannot start an HTML character reference. WordPress runs the post content of a font record through KSES for a user without unfiltered_html, which is the normal case on multisite, and KSES rewrites those characters. The escape keeps the name unchanged:
@font-face{font-family:"\3c /style\3e \3c script\3e alert(1)\3c /script\3e ";}
A hexadecimal escape uses the shortest digit sequence and always ends with one space, because wp_kses_no_null() removes a backslash that zeros follow.
A plain font name still works. O'Reilly Sans and O"Reilly Sans are not valid CSS, but earlier versions accepted them and the current upload client sends them. The compatibility path reads such a value as one name. It rejects a value that holds CSS syntax outside a quoted name, so "A"; color:red is an error.
Invalid input returns an error instead of a repaired value. WP_Font_Utils::sanitize_font_family() returns an empty string, and the REST controllers return a 400 error. Earlier code turned Rock 3D</style><script>alert('XSS');</script> into "Rock 3D". It now rejects the value. generic(font[name]) is also invalid CSS and is now rejected.
The font face slug changes only for names that were already broken. The comparison key uses the decoded names. A plain name such as open sans or open sans,serif produces the same slug as before, so an existing record keeps its slug. A name that holds % \ ; , & < > produces a percent sequence in the key, for example acme%2c sans. Those names could not round-trip at all before this change.
KSES keeps its existing policy for every other value. A font-family value that the grammar rejects still goes through the current checks, so font-family: var(--wp--preset--font-family--inter) still works. In a style attribute a semicolon outside a string still separates declarations, so font-family:"A;B";color:red keeps both declarations while font-family: "A"; color:red keeps both too. The REST fontFamily field is a single value and rejects the second form.
Gutenberg dependency
Core does not require the escape scheme of Gutenberg PR #76782. The two Trac attachments, O'Reilly Sans and O"Reilly Sans, both work with the current upload client through the plain name path.
This PR also fixes the first "Known issue" that Gutenberg PR #76782 records. Core no longer collapses the whitespace that ends a Unicode escape, so the escaped CSS string that the PR sends now decodes without loss:
"\22 Ephesis\22 font with \3C special \5C \3E {chars} \26 things\2C ya'know?"
decodes to: "Ephesis" font with <special \> {chars} & things, ya'know?
Gutenberg PR #76782 is still the companion change for a font whose metadata name holds a character that the plain name path rejects, such as a comma, a parenthesis, or an angle bracket. A client must serialize such a name as a CSS string.
Not fixed here: the second "Known issue" of that PR. The family controller still stores the display name in post_title with sanitize_text_field(), so a display name that holds markup still loses that text. The display name is a label and not the CSS identity, so the font works. A change to display-name storage needs a fallback for existing titles and its own migration, so it belongs in a separate ticket.
Testing
Automated
New test files:
tests/phpunit/tests/fonts/wpCssFontFamily.php— the parser and the serializer: the grammar, negative cases, equivalent escape forms, round trips, and long input.tests/phpunit/tests/fonts/fontFamilyDataPath.php— the complete PHP data path: REST create and read, the JSON that the posts store, the preset CSS, the@font-faceCSS, three save and read cycles, duplicate detection, validation errors, a seeded legacy record, and injection tests.
Extended test files: sanitizeFontFamily.php (the complete semantic matrix of the ticket), getFontFaceSlug.php, generateAndPrint.php, wp-font-face-tests-dataset.php, getFontsFromThemeJson.php, wpFontCollection/getData.php, both REST controller tests, kses.php, and wpFilterGlobalStylesPost.php.
Commands and results on this branch:
npm run test:php -- --group fonts 490 tests, 1548 assertions (6 pre-existing network failures) npm run test:php -- --group kses OK (500 tests, 1575 assertions) npm run test:php -- --group restapi-global-styles OK (144 tests, 475 assertions) npm run test:php -- --filter Tests_Theme_wpThemeJson OK (295 tests, 618 assertions) npm run test:php -- --filter Tests_Theme_WpThemeJsonResolver OK (40 tests, 157 assertions) npm run test:php -- -c tests/phpunit/multisite.xml --group fonts 491 tests (same 6 pre-existing failures) npm run test:php -- -c tests/phpunit/multisite.xml --group kses OK (500 tests, 1575 assertions) npm run test:php 26576 tests, 4 errors, 30 failures ./vendor/bin/phpcs --standard=phpcs.xml.dist no errors, no warnings ./vendor/bin/phpcs --standard=phpcompat.xml.dist no errors (testVersion 7.4-) ./vendor/bin/phpstan analyze OK, no errors
Every error and failure also happens on an unmodified trunk in the same environment. They come from two causes that this PR does not touch:
- The environment has no outbound DNS. This breaks
Tests_HTTP_HTTP::test_wp_http_validate_url_should_validate,WP_Test_REST_Attachments_Controller::test_create_item_from_url_*,Tests_REST_WpRestUrlDetailsController,Tests_Fonts_WpFontCollection_GetData::test_should_*_json_url, andTests_REST_WpRestFontFacesController::test_create_item_sanitize_font_face_settings, whosesrcvalue must passwp_http_validate_url(). Tests_Script_Modules_WpScriptModules::test_default_script_module_files_existneeds a build artifact that is not present.
I confirmed the identical failure set on a clean trunk for --group restapi and --group font-library.
Parser expectations checked against a browser
I did not use the new PHP parser as the only reference for its own tests. I compared 29 values against Chrome's CSS parser through CSSStyleDeclaration, and checked that Chrome reads the input value and the serialized output as the same value. 27 values agree. The two exceptions confirm the expectations rather than contradict them:
Arial, Rock 3D , Open Sans,serif— Chrome rejects the value, because3Dcannot start an identifier. The new strict parser rejects it too. Only the documented plain name path accepts it, which is the earlier WordPress behavior.Inter, generic(kai)— Chrome does not implementgeneric(). Core keeps its current support for that value.
Browser check of actual font use
Environment: this repository at a5795c3, Twenty Twenty-Five, Chrome 143, the local Docker environment, an administrator account. The font file is DMSans-Regular.woff2 from tests/phpunit/data (SIL Open Font License).
I seeded a font family and a font face through the REST routes, with the value "O'Reilly, Sans", serif. This name holds both an apostrophe and a comma. I activated it through the global styles REST route. The generated public page holds:
--wp--preset--font-family--trac-63568: "O'Reilly, Sans", serif; @font-face{font-family:"O'Reilly, Sans";font-style:normal;font-weight:400;font-display:fallback;src:url('.../test-63568.woff2') format('woff2');}
In the browser:
document.fonts.load('400 16px "O\'Reilly, Sans"')returns one face withfamily === "O'Reilly, Sans"andstatus === 'loaded'.- Canvas glyph metrics for the preset name are
width 428.28, ascent 29. A control that loads the same file throughnew FontFace('Trac63568Control', ...)measures exactly the same.serifmeasures401.445andsans-serifmeasures435.801. The browser therefore uses the uploaded font and not a fallback. - The checks pass again after a page reload, the font file returns HTTP 200, and the console holds no message.
- The editor canvas settings hold
--wp--preset--font-family--trac-63568: "O'Reilly, Sans", serif.
I repeated the seed with the name "</STYLE><script>window.trac63568=1;</script>Sans". The page holds one style element, no script element carries the text, window.trac63568 stays undefined, and the browser still reads the complete decoded name back and loads the face.
Tests that I did not run
- The Site Editor upload workflow through the interface. That needs an authenticated browser session, which I did not create. The REST path that the interface uses is covered by the integration tests and by the browser check above.
- A Playwright spec.
tests/e2eneeds the same authenticated environment, and the font library interface belongs to the Gutenberg package. The browser evidence above uses the REST path instead, which tests core independently of the upload client. - Firefox and WebKit. Only Chrome was available. Report these as unverified, not as a pass.
- The manual acceptance check with the two Trac attachment font files. I checked their names (
O'Reilly SansandO"Reilly Sans) through the complete PHP path, but not the files themselves. - CI. No workflow result was available when I opened this PR.
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5
Used for: The parser and serializer implementation, the caller changes, the tests, and this description. I ran every test and every check reported above and reviewed the complete diff.
#61
@
6 weeks ago
Tested PR 13610 at 7c82a49985545e1aa65cee06622b63303857ace1 against base 74bb9334f5129ad64bab5b630157067bf5f24931.
Results:
- Focused single-site run for fonts, kses, and restapi-global-styles: 1,169 tests, 3,698 assertions, passed.
- Focused multisite run for fonts, kses, and restapi-global-styles: 1,170 tests, 3,701 assertions, passed.
- Focused css-font-family single-site profile: 107 tests, 299 assertions, passed.
- Focused css-font-family multisite profile: 107 tests, 299 assertions, passed.
These results support the current patch for the shared font-family parsing and serialization path, including the REST/global styles, KSES, and single-site/multisite coverage touched by the change.
I did not attach screenshots here. The useful evidence for this pass is the automated coverage against the current PR head, rather than a generic browser health screenshot.
@mmaattiiaass commented on PR #13610:
5 weeks ago
#62
Testing evidence: font upload, end to end
These two videos show the same flow on trunk and on this branch:
- Upload four fonts in Styles → Typography → Manage fonts → Upload.
- Set each font on one Global Styles element, then save.
- Open the website and check the font that the browser really uses.
The internal metadata names of the four test fonts are O'Reilly Sans, Tom & Jerry, 12345, and ACME, Sans. Each font has glyphs that look very different from the default serif fallback, so a fallback is easy to see. At the end, a panel shows the @font-face CSS that WordPress prints, the rules that Chromium accepts (CSSOM), and the font of each element (getComputedStyle + document.fonts).
Setup: wordpress-develop Docker environment, Twenty Twenty-Five, Chromium, Playwright. The upload client is the editor bundle that this repository builds.
Before: trunk at 88b2d10354 (the base of this branch)
https://github.com/user-attachments/assets/25614237-e145-4e9a-8510-94cb82b5309a
- The editor shows all four fonts correctly, but the website shows a fallback font for all four.
- WordPress prints
font-family:O'Reilly Sans;. The apostrophe opens a CSS string, so Chromium also drops the next two rules (Tom & JerryandACME). Chromium accepts only 4 of 6 rules, and two of them have nofont-family. - Chromium rejects the unquoted
font-family:12345;descriptor.
After: this branch at 6913a32d02
https://github.com/user-attachments/assets/7e01b176-dca3-4448-8e7c-e4cb87d2e327
| Element | Font name | Trunk | This branch |
|---|---|---|---|
| Headings | O'Reilly Sans | fallback | ✔ uploaded font |
| Text | Tom & Jerry | fallback | ✔ uploaded font |
| Buttons | 12345 | fallback | ✔ uploaded font |
| Links | ACME, Sans | fallback | ⚠ font loads, but the name changes to ACME
|
- WordPress prints valid quoted names, for example
"O'Reilly Sans"and"Tom \26 Jerry". Chromium accepts all six@font-facerules. ACME, Sansstill changes toACME, because the upload client sends the comma name as a CSS list. That case needs https://github.com/WordPress/gutenberg/pull/76782.
Limits: I recorded in Chromium only. I did not test Firefox or WebKit. The test fonts are not the Trac attachments: I made them from fonts with the SIL Open Font License (Ephesis, IBM Plex Mono, Beiruti, Jost) and changed only their internal names.
@mmaattiiaass commented on PR #13610:
5 weeks ago
#63
Testing evidence: 86 edge-case fonts in Chromium, Chrome, and Firefox
These videos test all the fonts from trac-63568-edge-case-fonts.zip with the steps of the font name test guide in the description. For each case, the video does these steps:
- A script deletes all fonts.
- The video uploads the case font in Appearance → Fonts → Upload.
- A script sets the font as the body text font in Global Styles.
- The video opens the home page and runs four checks:
- The stored
fontFamilydecodes to one font name with the exact text of the case (step 7). document.fonts.load()finds a loaded face with that name (step 5).- Text in that name has the same width as text in the control font (step 6).
- The body text on the page has the same width as the control font.
- The stored
Case 1 plays at normal speed. Cases 2–87 play at 5× speed, with a scoreboard. Each video ends with a summary table that compares each case with the guide.
Setup: wordpress-develop Docker environment, Twenty Twenty-Five, Playwright 1.61.1. The core upload client is the Gutenberg build that trunk pins (5715a61).
| Setup | Chromium 149 | Chrome 153 | Firefox 151 |
|---|---|---|---|
trunk at 57c4558589 | 29 of 57 | 29 of 57 | 29 of 57 |
This PR at 88508e2613 | 57 of 57 | 57 of 57 | 57 of 57 |
This PR + #76782 at 86cf7bad0dc | 57 of 57 | 57 of 57 | 57 of 57 |
The table shows how many of the 57 cases that must work pass. In all nine runs, each of the 86 cases gives the result that the guide shows.
trunk at 57c4558589
Chromium 149
https://github.com/user-attachments/assets/e5a542c1-6ec3-415b-9fc0-14659bd290c2
Chrome 153
https://github.com/user-attachments/assets/e37f58b4-5ffd-4418-9ce4-64d29ef25090
Firefox 151
https://github.com/user-attachments/assets/ba6a88f7-e00e-4860-acc3-6768c8898ac5
This PR at 88508e2613
Chromium 149
https://github.com/user-attachments/assets/7f4eaa82-3e49-46d3-acf9-6a3643e55320
Chrome 153
https://github.com/user-attachments/assets/2627da71-cb12-41a5-b168-1c39e7203710
Firefox 151
https://github.com/user-attachments/assets/eb5f95d0-1670-48c5-8bb4-f8e4f0d17c51
This PR + Gutenberg PR #76782 at 86cf7bad0dc
Chromium 149
https://github.com/user-attachments/assets/ddb5fc63-d744-474a-8289-6af079cc5644
Chrome 153
https://github.com/user-attachments/assets/2030dfd9-6a38-436b-ae89-bd1ba7a56b01
Firefox 151
https://github.com/user-attachments/assets/a951ac45-eb2a-436c-aaad-5f3ba9f7f285
Notes
- Case 67 (
A[U+000A]B) in Firefox: with the core upload client, the editor sends no REST request and shows no notice. Chromium and Chrome upload the font, but with a wrong name. Both results fail, as the guide shows. With #76782, the case works in all three browsers. - Cases 54 and 55: all three browsers render the text in the uploaded font, because they do not use
emojiandfangsongas generic keywords yet. With the core upload client, these cases fail step 7. - The script writes the body font directly to the global styles post, as an admin save does. It does not use the Styles UI.
- I did not test WebKit or Safari.
@mmaattiiaass commented on PR #13610:
5 weeks ago
#64
Testing evidence: font upload, end to end
These two videos show the same flow on trunk and on this branch:
- Upload four fonts in Styles → Typography → Manage fonts → Upload.
- Set each font on one Global Styles element, then save.
- Open the website and check the font that the browser really uses.
The internal metadata names of the four test fonts are O'Reilly Sans, Tom & Jerry, 12345, and ACME, Sans. Each font has glyphs that look very different from the default serif fallback, so a fallback is easy to see. At the end, a panel shows the @font-face CSS that WordPress prints, the rules that Chromium accepts (CSSOM), and the font of each element (getComputedStyle + document.fonts).
Setup: wordpress-develop Docker environment, Twenty Twenty-Five, Chromium, Playwright. The upload client is the editor bundle that this repository builds.
Before: trunk at 88b2d10354 (the base of this branch)
https://github.com/user-attachments/assets/25614237-e145-4e9a-8510-94cb82b5309a
- The editor shows all four fonts correctly, but the website shows a fallback font for all four.
- WordPress prints
font-family:O'Reilly Sans;. The apostrophe opens a CSS string, so Chromium also drops the next two rules (Tom & JerryandACME). Chromium accepts only 4 of 6 rules, and two of them have nofont-family. - Chromium rejects the unquoted
font-family:12345;descriptor.
After: this branch at 6913a32d02
https://github.com/user-attachments/assets/7e01b176-dca3-4448-8e7c-e4cb87d2e327
| Element | Font name | Trunk | This branch |
|---|---|---|---|
| Headings | O'Reilly Sans | fallback | ✔ uploaded font |
| Text | Tom & Jerry | fallback | ✔ uploaded font |
| Buttons | 12345 | fallback | ✔ uploaded font |
| Links | ACME, Sans | fallback | ⚠ font loads, but the name changes to ACME
|
- WordPress prints valid quoted names, for example
"O'Reilly Sans"and"Tom \26 Jerry". Chromium accepts all six@font-facerules. ACME, Sansstill changes toACME, because the upload client sends the comma name as a CSS list. That case needs https://github.com/WordPress/gutenberg/pull/76782.
Limits: I recorded in Chromium only. I did not test Firefox or WebKit. The test fonts are not the Trac attachments: I made them from fonts with the SIL Open Font License (Ephesis, IBM Plex Mono, Beiruti, Jost) and changed only their internal names.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)





Savate font, but the font name has been changed to "O'Reilly Sans" using FontForge