Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#60613 closed defect (bug) (fixed)

Theme JSON CSS var preset resolution: check for null values

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

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.


3 years 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
3 years 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:


3 years ago
#3

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

#4 @swissspidy
3 years ago

  • Component General → Themes
  • Owner set to youknowriad
  • Status new → reviewing

#5 @youknowriad
3 years ago

  • Resolution → fixed
  • Status reviewing → 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.