Skip to content
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

HTML API: Guard against non-string attribute values. #55368

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/experimental/interactivity-api/directive-processing.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ function gutenberg_interactivity_evaluate_reference( $path, array $context = arr
);

/*
* Check first if the directive path is preceded by a negator operator (!),
* Check first if the directive path is preceded by a negation operator (!),
* indicating that the value obtained from the Interactivity Store (or the
* passed context) using the subsequent path should be negated.
*/
$should_negate_value = '!' === $path[0];
$should_negate_value = strlen( $path ) > 0 && '!' === $path[0];

$path = $should_negate_value ? substr( $path, 1 ) : $path;
$path_segments = explode( '.', $path );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function gutenberg_interactivity_process_wp_bind( $tags, $context ) {
}

$expr = $tags->get_attribute( $attr );
$expr = is_string( $expr ) ? $expr : '';
$value = gutenberg_interactivity_evaluate_reference( $expr, $context->get_context() );
$tags->set_attribute( $bound_attr, $value );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function gutenberg_interactivity_process_wp_class( $tags, $context ) {
}

$expr = $tags->get_attribute( $attr );
$expr = is_string( $expr ) ? $expr : '';
$add_class = gutenberg_interactivity_evaluate_reference( $expr, $context->get_context() );
if ( $add_class ) {
$tags->add_class( $class_name );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function gutenberg_interactivity_process_wp_context( $tags, $context ) {
}

$value = $tags->get_attribute( 'data-wp-context' );
if ( null === $value ) {
if ( ! is_string( $value ) || empty( $value ) ) {
// No data-wp-context directive.
return;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/experimental/interactivity-api/directives/wp-style.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ function gutenberg_interactivity_process_wp_style( $tags, $context ) {
}

$expr = $tags->get_attribute( $attr );
$expr = is_string( $expr ) ? $expr : '';
$style_value = gutenberg_interactivity_evaluate_reference( $expr, $context->get_context() );
if ( $style_value ) {
$style_attr = $tags->get_attribute( 'style' );
$style_attr = is_string( $style_value ) ? $style_attr : '';
$style_attr = gutenberg_interactivity_set_style( $style_attr, $style_name, $style_value );
$tags->set_attribute( 'style', $style_attr );
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function gutenberg_interactivity_process_wp_text( $tags, $context ) {
}

$value = $tags->get_attribute( 'data-wp-text' );
if ( null === $value ) {
if ( ! is_string( $value ) || empty( $value ) ) {
return;
}

Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/cover/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function render_block_core_cover( $attributes, $content ) {
$processor->next_tag();

$styles = $processor->get_attribute( 'style' );
$styles = is_string( $styles ) ? $styles : '';
$merged_styles = ! empty( $styles ) ? $styles . ';' : '';
$merged_styles .= 'background-image:url(' . esc_url( $current_featured_image ) . ');';

Expand Down
Loading