Repository navigation
Conversation
Code that holds CSS text and must check it is one value of a type, such as the transform value checks in the style engine, theme.json, block supports and safecss_filter_attr(), needs the text's single token or a rejection. Each wrote its own loop over the tokenizer. The method ignores whitespace and comments around the token, as CSS Syntax 3 discards whitespace around a component value and drops comments while tokenizing. A caller that must reject surrounding whitespace compares the token's length with the text's.
|
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: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Whitespace or a comment before or after the token now returns null, as does input that is only whitespace or a comment. Callers check values that must be one token, such as a stored `rotate` angle, and some write the value back as given; accepting surrounding whitespace or comments would let that text through unchecked.
…arse-single-token
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Caution
This is a work in progress draft and is not ready for any serious review.
Add
WP_CSS_Token_Processor::parse_single_token( $css ), which returns the token when the CSS is exactly one token other than whitespace or a comment, andnullotherwise. Code that holds CSS text and must check it is one value of a type needs this: the transform value checks in #100 call it from the style engine,WP_Theme_JSON, block supports andsafecss_filter_attr(), each through its own tokenizer loop.45deg45deg␠45deg␠null/* a */1pxnull1px 2pxnullcalc(1px)null(three tokens)nullWhitespace or a comment around the token returns
null. Callers such as the style engine in #100 write the value back as given, so text around the token would reach the output unchecked. This differs from CSS Syntax 3, which discards whitespace around a component value.The method returns a token, not a component value: a function such as
calc(1px)is not one token. With #110, an angle check is$token = WP_CSS_Token_Processor::parse_single_token( $value ); $is_angle = null !== $token && $token->is_angle();.Tests cover each case above. The
css-apigroup passes (1028 tests); PHPCS and PHPStan are clean.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.