From 8f8c7eb13d4e766a4011c30b053a659367718707 Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Thu, 6 Jun 2024 11:53:49 +0200 Subject: [PATCH] Add test to cover existing issue --- src/wp-includes/class-wp-block.php | 1 + tests/phpunit/tests/block-bindings/render.php | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/wp-includes/class-wp-block.php b/src/wp-includes/class-wp-block.php index 02ce8cd62d750..c6ca8a3bd42be 100644 --- a/src/wp-includes/class-wp-block.php +++ b/src/wp-includes/class-wp-block.php @@ -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( diff --git a/tests/phpunit/tests/block-bindings/render.php b/tests/phpunit/tests/block-bindings/render.php index 087abb1bdf30c..09c6fb50075fb 100644 --- a/tests/phpunit/tests/block-bindings/render.php +++ b/tests/phpunit/tests/block-bindings/render.php @@ -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 = << +

Default content

+ +HTML; + $parsed_blocks = parse_blocks( $block_content ); + $block = new WP_Block( $parsed_blocks[0] ); + $result = $block->render(); + + $this->assertSame( + '

$12.50

', + 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.