Skip to content

Fonts: Escape axis tags in font-variation-settings arrays - #104

Open
sirreal wants to merge 2 commits into
css-api/css-token-processor-foundationsfrom
css-api/font-variation-tags
Open

sirreal wants to merge 2 commits into
css-api/css-token-processor-foundationsfrom
css-api/font-variation-tags

Conversation

@sirreal

@sirreal sirreal commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Caution

This is a work in progress draft and is not ready for any serious review.

WP_Font_Face::compile_variations() writes each axis of a font-variation-settings array as sprintf( '"%s" %s', $tag, $value ) since r63653 (https://core.trac.wordpress.org/ticket/66103). The tag is put in quotes without escaping and the value is not checked, so a tag with a quotation mark ends the string early:

Settings Trunk This branch
array( 'wght' => 400 ) "wght" 400 "wght" 400
array( 'wg"t' => 400 ) "wg"t" 400 "wg\22 t" 400
array( 'wght' => '400px' ) "wght" 400px axis skipped

The tag is written with WP_CSS_Builder::string(). An axis is skipped unless its tag is four characters from U+0020 to U+007E, which CSS Fonts 4 requires of an axis tag, and its value is one CSS number token, read with WP_CSS_Token_Processor. When every axis is skipped, the descriptor is omitted.

A value such as calc(400) is valid CSS for the descriptor but is skipped; the array form is a PHP API, and numbers are what callers pass.

WordPress#13610 does not change compile_variations().

The string form of font-variation-settings and the other @font-face descriptors are written as they are; this PR does not change them.

Depends on WordPress#14781.

Trac ticket: TBD

Use of AI Tools

AI assistance: Yes
Tools: Claude Code
Models: Claude Opus 5.5
Used for: implementation, tests and this description.


This pull request is for code review only. Keep other discussion in the Trac ticket. Do not merge. See GitHub Pull Requests for Code Review in the Core Handbook.

WP_Font_Face::compile_variations() writes each axis as
sprintf( '"%s" %s', $tag, $value ) since r63653. Neither part is
escaped or validated, so a tag holding `"` ends the string early and
the rest of the tag and the value are written as CSS:

    array( 'wght' => 400 )      -> "wght" 400
    array( 'wg"t' => 400 )      -> "wg"t" 400

The tag is written with WP_CSS_Builder::string(), and an axis is
skipped unless its tag is four characters from U+0020 to U+007E, as
CSS Fonts 4 requires, and its value reads as one CSS number token.
Values such as `400px` or `calc(400)` are skipped; the descriptor
takes a <number>, and calc() is the only other form CSS accepts there.
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jonsurrell.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

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.

1 participant