Make WordPress Core

Opened 12 days ago

Closed 10 days ago

#66427 closed defect (bug) (fixed)

Block Supports: Allow CSS custom properties in wp_sanitize_block_gap_value()

Reported by: noruzzaman Owned by: isabel_brison
Priority: normal Milestone: 7.2
Component: Editor Version: trunk
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses: css, tests

Description

When a theme defines a preset block gap in theme.json (such as styles.spacing.blockGap: "var:preset|spacing|32"):

  1. wp_get_global_styles() resolves the preset to its CSS variable format: var(--wp--preset--spacing--32).
  2. Candidate values for the global block gap in layout rendering are passed through wp_sanitize_block_gap_value().
  3. Because wp_sanitize_block_gap_value() disallows parentheses to prevent CSS injection, the resolved preset is rejected and returns null.
  4. As a result, Grid layout calculations in wp_get_layout_style() fall back to 0.5em instead of using the theme's preset gap value.
  5. In Grid blocks with columnCount and minimumColumnWidth, columns stack into a single column.

Fix: Allow valid CSS custom property references matching /^var\(--[a-zA-Z0-9_-]+\)$/.

Gutenberg PR: ​https://github.com/WordPress/gutenberg/pull/82817

Change History (3)

This ticket was mentioned in ​PR #15277 on ​WordPress/wordpress-develop by ​@noruzzaman.


12 days ago
#1

  • Keywords has-patch has-unit-tests added

Gutenberg PR: ​https://github.com/WordPress/gutenberg/pull/82817

Description

Allows valid CSS custom property references (such as var(--wp--preset--spacing--32)) in wp_sanitize_block_gap_value().

When a theme defines a preset block gap in theme.json (such as styles.spacing.blockGap: "var:preset|spacing|32"):

  1. wp_get_global_styles() resolves the preset to its CSS variable format: var(--wp--preset--spacing--32).
  2. Candidate values for the global block gap in layout rendering are passed through wp_sanitize_block_gap_value().
  3. Because wp_sanitize_block_gap_value() disallows parentheses to prevent CSS injection, the resolved preset was rejected and returned null.
  4. As a result, Grid layout calculations in wp_get_layout_style() fell back to 0.5em instead of using the theme's preset gap value.
  5. In Grid blocks with columnCount and minimumColumnWidth, columns stack into a single column.

Testing Instructions

  1. Run PHPUnit test suite:
    npm run test:php -- tests/phpunit/tests/block-supports/layout.php
    
  1. Verify all tests pass including CSS variable preset sanitization and grid layout fallback.

#2 @isabel_brison
10 days ago

  • Milestone Awaiting Review → 7.2
  • Owner set to isabel_brison
  • Status new → assigned

#3 @isabel_brison
10 days ago

  • Resolution → fixed
  • Status assigned → closed

In 65212:

Editor: allow CSS custom properties in block gap values.

Ensures wp_sanitize_block_gap_value allows custom property strings so they can applied in responsive grid layout calculations.

Props noruzzaman.
Fixes #66427.

Note: See TracTickets for help on using tickets.