Skip to content

Commit

Permalink
Add test to cover existing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
SantosGuillamot committed Jun 6, 2024
1 parent efa5bae commit 8f8c7eb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/wp-includes/class-wp-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ private function replace_html( string $block_content, string $attribute_name, $s
}
$block_reader->release_bookmark( 'iterate-selectors' );
return $block_content;

case 'attribute':
$amended_content = new WP_HTML_Tag_Processor( $block_content );
if ( ! $amended_content->next_tag(
Expand Down
36 changes: 36 additions & 0 deletions tests/phpunit/tests/block-bindings/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,42 @@ public function test_source_value_with_unsafe_html_is_sanitized() {
);
}

/**
* Tests that including symbols and numbers works well with bound attributes.
*
* @ticket 61385
*
* @covers WP_Block::process_block_bindings
*/
public function test_using_symbols_in_block_bindings_value() {
$get_value_callback = function () {
return '$12.50';
};

register_block_bindings_source(
self::SOURCE_NAME,
array(
'label' => self::SOURCE_LABEL,
'get_value_callback' => $get_value_callback,
)
);

$block_content = <<<HTML
<!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"test/source"}}}} -->
<p>Default content</p>
<!-- /wp:paragraph -->
HTML;
$parsed_blocks = parse_blocks( $block_content );
$block = new WP_Block( $parsed_blocks[0] );
$result = $block->render();

$this->assertSame(
'<p>$12.50</p>',
trim( $result ),
'The block content should properly show the symbol and numbers.'
);
}

/**
* Tests if the `__default` attribute is replaced with real attribues for
* pattern overrides.
Expand Down

0 comments on commit 8f8c7eb

Please sign in to comment.