Make WordPress Core

Opened 7 months ago

Closed 7 months ago

Last modified 7 months ago

#60613 closed defect (bug) (fixed)

Theme JSON CSS var preset resolution: check for null values

Reported by: ramonopoly's profile ramonopoly Owned by: youknowriad's profile youknowriad
Milestone: 6.5 Priority: normal
Severity: normal Version: 6.5
Component: Themes Keywords: has-patch has-unit-tests gutenberg-merge
Focuses: Cc:

Description

When using wp_get_global_styles() with the resolve-variables flag like this —

wp_get_global_styles( array( 'typography', 'fontSize' ), array( 'block_name' => 'core/search', 'transforms' => array( 'resolve-variables' ) ) );

It's possible to trigger the following error:


Deprecated: strpos(): Passing null to parameter 1 ($haystack) of type string is deprecated in

Deprecated: preg_match_all(): Passing null to parameter 2 ($subject) of type string is deprecated


The complaint is about passing a null value to strpos() and preg_match_all() in WP_Theme_JSON::convert_variables_to_value

wp_get_global_styles attempt to resolve variables using merged data from WP_Theme_JSON_Resolver.

WP_Theme_JSON_Resolver::get_block_data() sets blockGap for supported blocks to null if the value is not defined.

Because WP_Theme_JSON_Gutenberg::convert_variables_to_value is expecting strings as values, it will trigger the error in this case.

Gutenberg PR: Theme JSON: Check for null values to cater for blockGap

Change History (7)

This ticket was mentioned in PR #6169 on WordPress/wordpress-develop by @ramonopoly.


7 months ago
#1

Syncs changes from

When resolving theme.json preset variables, add a check to make sure the value is not empty before we run it through strpos() and preg_match_all().

Run the tests:

npm run test:php -- --filter Tests_Theme_wpThemeJson

Trac ticket: https://core.trac.wordpress.org/ticket/60613

#2 @ramonopoly
7 months ago

I added 6.5 to this ticket - hopefully it's not controversial.

Fine to be punted to 6.6.

@get_dave commented on PR #6169:


7 months ago
#3

@youknowriad I think this one is ready once the nits are addressed.

#4 @swissspidy
7 months ago

  • Component changed from General to Themes
  • Owner set to youknowriad
  • Status changed from new to reviewing

#5 @youknowriad
7 months ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 57716:

Editor: Check for null values in Theme JSON to cater for blockGap.

When resolving theme.json preset variables, add a check to make sure the value is not empty before we run it through strpos() and preg_match_all().

Props ramonopoly, mukesh27, get_dave.
Fixes #60613.

Note: See TracTickets for help on using tickets.