From b99212fdf27e203b518fc42b267395c5a6939669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 10 Oct 2025 17:49:14 +0200 Subject: [PATCH] [BlockMarkupProcessor] Preserve self-closing block style when rewriting URLs --- .../BlockMarkup/class-blockmarkupprocessor.php | 3 ++- .../Tests/BlockMarkupProcessorTest.php | 18 ++++++++++++++++++ .../Tests/BlockMarkupUrlProcessorTest.php | 5 +++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/components/DataLiberation/BlockMarkup/class-blockmarkupprocessor.php b/components/DataLiberation/BlockMarkup/class-blockmarkupprocessor.php index 9e0f9267..96d7a8ac 100644 --- a/components/DataLiberation/BlockMarkup/class-blockmarkupprocessor.php +++ b/components/DataLiberation/BlockMarkup/class-blockmarkupprocessor.php @@ -496,7 +496,8 @@ private function block_attribute_updates_to_modifiable_text_updates() { ' ' . $this->block_name . ' ' . - $encoded_attributes + $encoded_attributes . + ( $this->is_self_closing_block() ? '/' : '' ) ); return true; diff --git a/components/DataLiberation/Tests/BlockMarkupProcessorTest.php b/components/DataLiberation/Tests/BlockMarkupProcessorTest.php index 69c07005..325d9925 100644 --- a/components/DataLiberation/Tests/BlockMarkupProcessorTest.php +++ b/components/DataLiberation/Tests/BlockMarkupProcessorTest.php @@ -358,6 +358,24 @@ public function test_set_block_attribute_value_updates_a_list_value() { ); } + public function test_set_block_attribute_value_updates_a_list_value_with_a_self_closing_block() { + $p = new BlockMarkupProcessor( + '' + ); + $this->assertTrue( $p->next_token(), 'Failed to find the block opener' ); + $this->assertTrue( $p->next_block_attribute(), 'Failed to find the first block attribute' ); + $this->assertTrue( $p->next_block_attribute(), 'Failed to find the second block attribute' ); + $this->assertTrue( $p->next_block_attribute(), 'Failed to find the third block attribute' ); + + $p->set_block_attribute_value( 'medium.png' ); + $this->assertEquals( 'medium.png', $p->get_block_attribute_value(), 'Failed to find the block attribute value' ); + $this->assertEquals( + '', + $p->get_updated_html(), + 'Failed to update the block attribute value' + ); + } + public function test_set_block_attribute_can_be_called_multiple_times() { $p = new BlockMarkupProcessor( '' diff --git a/components/DataLiberation/Tests/BlockMarkupUrlProcessorTest.php b/components/DataLiberation/Tests/BlockMarkupUrlProcessorTest.php index af8eb1fb..f7b94b82 100644 --- a/components/DataLiberation/Tests/BlockMarkupUrlProcessorTest.php +++ b/components/DataLiberation/Tests/BlockMarkupUrlProcessorTest.php @@ -193,6 +193,11 @@ public static function provider_test_set_url_examples() { 'https://w.org', '', ), + 'In the "url" block attribute of a navigation-link block' => array( + '', + 'https://w.org', + '', + ), 'In a text node' => array( 'Have you seen https://wordpress.org yet?', 'https://w.org',