Block Supports: Allow CSS custom properties in block gap sanitization - #82817
Open
noruzzamans wants to merge 2 commits into
Open
noruzzamans wants to merge 2 commits into
noruzzamans wants to merge 2 commits into
Conversation
Ensures gutenberg_sanitize_block_gap_value() accepts valid CSS custom property references such as var(--wp--preset--spacing--*). This fixes an issue where Grid layout calculations fell back to 0.5em when using global theme.json blockGap presets on capped columns. Fixes WordPress#82747.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
6 tasks
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.
What?
Closes #82747
Allows valid CSS custom property references (such as
var(--wp--preset--spacing--32)) ingutenberg_sanitize_block_gap_value().Why?
When a theme defines a preset block gap in
theme.json(such asstyles.spacing.blockGap: "var:preset|spacing|32"):gutenberg_get_global_styles()resolves the preset to its CSS variable format:var(--wp--preset--spacing--32).gutenberg_render_layout_support_flag()are passed throughgutenberg_sanitize_block_gap_value().gutenberg_sanitize_block_gap_value()disallows parentheses(,)to prevent CSS injection, the resolved preset was rejected and returnednull.gutenberg_get_layout_style()fell back to0.5eminstead of using the theme's preset gap value.columnCountandminimumColumnWidth, the column calculation formulamax(min(..., 100%), (100% - (gap * (n - 1))) / n)was computed against0.5em, causing grid items to overflow or stack into a single column.How?
gutenberg_sanitize_block_gap_value()inlib/block-supports/layout.phpto accept valid CSS custom property references matching/^var\(--[a-zA-Z0-9_-]+\)$/.phpunit/block-supports/layout-test.phpcoveringgutenberg_sanitize_block_gap_value()with valid and invalid CSS variables, including nested array handling.data_gutenberg_get_layout_style()verifying that Grid layout with a preset CSS variable fallback correctly computes thegrid-template-columnsdeclaration.Testing Instructions
theme.json:columnCount: 2andminimumColumnWidth: "20rem".grid-template-columnsusesvar(--wp--preset--spacing--32)rather than falling back to0.5em.Use of AI Tools
AI assistance: Yes
Model(s): Gemini 3.8 Flash High
Assisted by Gemini 3.8 Flash High to investigate the root cause in
layout.phpand compose the PHPUnit test cases.