Make WordPress Core

Opened 13 hours ago

Last modified 13 hours ago

#66427 new defect (bug)

Block Supports: Allow CSS custom properties in wp_sanitize_block_gap_value()

Reported by: noruzzaman Owned by:
Priority: normal Milestone: Awaiting Review
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 (1)

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


13 hours 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.
Note: See TracTickets for help on using tickets.