-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Global Styles: Do not sanitize block style variations based on registration status #62405
Closed
aaronrobertshaw
wants to merge
1
commit into
trunk
from
remove/theme-json-validation-of-block-style-variations
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1463,12 +1463,14 @@ public function test_get_stylesheet_generates_fluid_typography_values() { | |
'default' | ||
); | ||
|
||
$stylesheet = $theme_json->get_stylesheet(); | ||
|
||
unregister_block_type( 'test/clamp-me' ); | ||
|
||
// Results also include root site blocks styles. | ||
$this->assertSame( | ||
':root{--wp--preset--font-size--pickles: clamp(14px, 0.875rem + ((1vw - 3.2px) * 0.156), 16px);--wp--preset--font-size--toast: clamp(14.642px, 0.915rem + ((1vw - 3.2px) * 0.575), 22px);}:where(body) { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }:where(.is-layout-flex){gap: 0.5em;}:where(.is-layout-grid){gap: 0.5em;}.is-layout-flow > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}.is-layout-flow > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}.is-layout-flow > .aligncenter{margin-left: auto !important;margin-right: auto !important;}.is-layout-constrained > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}.is-layout-constrained > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}.is-layout-constrained > .aligncenter{margin-left: auto !important;margin-right: auto !important;}.is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)){margin-left: auto !important;margin-right: auto !important;}body .is-layout-flex{display: flex;}.is-layout-flex{flex-wrap: wrap;align-items: center;}.is-layout-flex > :is(*, div){margin: 0;}body .is-layout-grid{display: grid;}.is-layout-grid > :is(*, div){margin: 0;}:root :where(body){font-size: clamp(0.875em, 0.875rem + ((1vw - 0.2em) * 0.156), 1em);}:root :where(h1){font-size: clamp(50.171px, 3.136rem + ((1vw - 3.2px) * 3.893), 100px);}:root :where(.wp-block-test-clamp-me){font-size: clamp(27.894px, 1.743rem + ((1vw - 3.2px) * 1.571), 48px);}.has-pickles-font-size{font-size: var(--wp--preset--font-size--pickles) !important;}.has-toast-font-size{font-size: var(--wp--preset--font-size--toast) !important;}', | ||
$theme_json->get_stylesheet() | ||
$stylesheet | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It turned out the deregistration of the test block before generating the stylesheet was causing this test to fail on this branch. Not 100% sure why yet but I'll look into that on Monday. |
||
); | ||
} | ||
|
||
|
@@ -3807,39 +3809,19 @@ public function test_sanitization() { | |
$this->assertEqualSetsWithIndex( $expected, $actual ); | ||
} | ||
|
||
public function test_sanitize_for_unregistered_style_variations() { | ||
$theme_json = new WP_Theme_JSON_Gutenberg( | ||
array( | ||
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA, | ||
'styles' => array( | ||
'blocks' => array( | ||
'core/quote' => array( | ||
'variations' => array( | ||
'unregisteredVariation' => array( | ||
'color' => array( | ||
'background' => 'hotpink', | ||
), | ||
), | ||
'plain' => array( | ||
'color' => array( | ||
'background' => 'hotpink', | ||
), | ||
), | ||
), | ||
), | ||
), | ||
), | ||
) | ||
); | ||
|
||
$sanitized_theme_json = $theme_json->get_raw_data(); | ||
$expected = array( | ||
public function test_unregistered_style_variations_are_omitted_from_block_style_nodes() { | ||
$theme_json_data = array( | ||
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA, | ||
'styles' => array( | ||
'blocks' => array( | ||
'core/quote' => array( | ||
'variations' => array( | ||
'plain' => array( | ||
'unregistered-variation' => array( | ||
'color' => array( | ||
'background' => 'hotpink', | ||
), | ||
), | ||
'plain' => array( | ||
'color' => array( | ||
'background' => 'hotpink', | ||
), | ||
|
@@ -3849,7 +3831,21 @@ public function test_sanitize_for_unregistered_style_variations() { | |
), | ||
), | ||
); | ||
$this->assertSameSetsWithIndex( $expected, $sanitized_theme_json, 'Sanitized theme.json styles does not match' ); | ||
|
||
$theme_json = new ReflectionClass( 'WP_Theme_JSON_Gutenberg' ); | ||
|
||
$func = $theme_json->getMethod( 'get_block_nodes' ); | ||
$func->setAccessible( true ); | ||
|
||
$nodes = $func->invoke( null, $theme_json_data ); | ||
$actual = $nodes[0]['variations']; | ||
$expected = array( | ||
array( | ||
'path' => array( 'styles', 'blocks', 'core/quote', 'variations', 'plain' ), | ||
'selector' => '.wp-block-quote.is-style-plain', | ||
), | ||
); | ||
$this->assertSameSetsWithIndex( $expected, $actual, 'Unregistered block style variations should not be included in block node data' ); | ||
} | ||
|
||
/** | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, what this PR does is:
This is the kind of thing that I mentioned: we are not removing sanitization but moving it everywhere. Each time we have to work with them, we need to make sure to use the ones that are registered.