mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-03-31 18:54:29 +00:00
Editor: Sanitize nested array in theme.json properly.
WP_Theme_JSON sanitization is now able to sanitize data contained on indexed arrays. So certain data from theme.json, for example, settings.typography.fontFamilies which is a JSON array will be sanitized. Props mmaattiiaass, mukesh27. Fixes #60360. git-svn-id: https://develop.svn.wordpress.org/trunk@57496 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -4978,4 +4978,139 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
|
||||
$actual
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that invalid properties are removed from the theme.json inside indexed arrays as settings.typography.fontFamilies.
|
||||
*
|
||||
* @ticket 60360
|
||||
*/
|
||||
public function test_sanitize_indexed_arrays() {
|
||||
$theme_json = new WP_Theme_JSON(
|
||||
array(
|
||||
'version' => '2',
|
||||
'badKey2' => 'I am Evil!',
|
||||
'settings' => array(
|
||||
'badKey3' => 'I am Evil!',
|
||||
'typography' => array(
|
||||
'badKey4' => 'I am Evil!',
|
||||
'fontFamilies' => array(
|
||||
'custom' => array(
|
||||
array(
|
||||
'badKey4' => 'I am Evil!',
|
||||
'name' => 'Arial',
|
||||
'slug' => 'arial',
|
||||
'fontFamily' => 'Arial, sans-serif',
|
||||
),
|
||||
),
|
||||
'theme' => array(
|
||||
array(
|
||||
'badKey5' => 'I am Evil!',
|
||||
'name' => 'Piazzolla',
|
||||
'slug' => 'piazzolla',
|
||||
'fontFamily' => 'Piazzolla',
|
||||
'fontFace' => array(
|
||||
array(
|
||||
'badKey6' => 'I am Evil!',
|
||||
'fontFamily' => 'Piazzolla',
|
||||
'fontStyle' => 'italic',
|
||||
'fontWeight' => '400',
|
||||
'src' => 'https://example.com/font.ttf',
|
||||
),
|
||||
array(
|
||||
'badKey7' => 'I am Evil!',
|
||||
'fontFamily' => 'Piazzolla',
|
||||
'fontStyle' => 'italic',
|
||||
'fontWeight' => '400',
|
||||
'src' => 'https://example.com/font.ttf',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'badKey8' => 'I am Evil!',
|
||||
'name' => 'Inter',
|
||||
'slug' => 'Inter',
|
||||
'fontFamily' => 'Inter',
|
||||
'fontFace' => array(
|
||||
array(
|
||||
'badKey9' => 'I am Evil!',
|
||||
'fontFamily' => 'Inter',
|
||||
'fontStyle' => 'italic',
|
||||
'fontWeight' => '400',
|
||||
'src' => 'https://example.com/font.ttf',
|
||||
),
|
||||
array(
|
||||
'badKey10' => 'I am Evil!',
|
||||
'fontFamily' => 'Inter',
|
||||
'fontStyle' => 'italic',
|
||||
'fontWeight' => '400',
|
||||
'src' => 'https://example.com/font.ttf',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$expected_sanitized = array(
|
||||
'version' => '2',
|
||||
'settings' => array(
|
||||
'typography' => array(
|
||||
'fontFamilies' => array(
|
||||
'custom' => array(
|
||||
array(
|
||||
'name' => 'Arial',
|
||||
'slug' => 'arial',
|
||||
'fontFamily' => 'Arial, sans-serif',
|
||||
),
|
||||
),
|
||||
'theme' => array(
|
||||
array(
|
||||
'name' => 'Piazzolla',
|
||||
'slug' => 'piazzolla',
|
||||
'fontFamily' => 'Piazzolla',
|
||||
'fontFace' => array(
|
||||
array(
|
||||
'fontFamily' => 'Piazzolla',
|
||||
'fontStyle' => 'italic',
|
||||
'fontWeight' => '400',
|
||||
'src' => 'https://example.com/font.ttf',
|
||||
),
|
||||
array(
|
||||
'fontFamily' => 'Piazzolla',
|
||||
'fontStyle' => 'italic',
|
||||
'fontWeight' => '400',
|
||||
'src' => 'https://example.com/font.ttf',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'name' => 'Inter',
|
||||
'slug' => 'Inter',
|
||||
'fontFamily' => 'Inter',
|
||||
'fontFace' => array(
|
||||
array(
|
||||
'fontFamily' => 'Inter',
|
||||
'fontStyle' => 'italic',
|
||||
'fontWeight' => '400',
|
||||
'src' => 'https://example.com/font.ttf',
|
||||
),
|
||||
array(
|
||||
'fontFamily' => 'Inter',
|
||||
'fontStyle' => 'italic',
|
||||
'fontWeight' => '400',
|
||||
'src' => 'https://example.com/font.ttf',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
$sanitized_theme_json = $theme_json->get_raw_data();
|
||||
$this->assertSameSetsWithIndex( $expected_sanitized, $sanitized_theme_json, 'Sanitized theme.json does not match' );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user