Skip to content

Commit 1f27ba2

Browse files
committed
KSES: Normalize closing block delimiter names. (#14120)
Trac ticket: Core-66208 See #13271 When `wp_kses()` was refactored, it introduced block name normalization, but only for opening and void block delimiters whose attributes were changed during sanitization. This left semantically-equivalent but mismatched delimiters. This patch enforces normalization for all block names inside block delimiters.
1 parent 7119e1b commit 1f27ba2

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎src/wp-includes/kses.php‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,7 @@ public function sanitize() {
16611661
$implicit_block_type = str_starts_with( $block_type, 'core/' )
16621662
? substr( $block_type, /* 'core/' */ 5 )
16631663
: $block_type;
1664+
$make_implicit = $block_type !== $implicit_block_type;
16641665

16651666
switch ( $block_processor->get_delimiter_type() ) {
16661667
// Track when blocks open and when they don’t self-close.
@@ -1691,6 +1692,7 @@ public function sanitize() {
16911692
// Filter block attributes for opening delimiters.
16921693
if ( $block_processor->opens_block() ) {
16931694
$original_attributes = $block_processor->allocate_and_return_parsed_attributes();
1695+
$voider = WP_Block_Processor::VOID === $block_processor->get_delimiter_type() ? '/' : '';
16941696

16951697
if ( isset( $original_attributes ) ) {
16961698
$filtered_attributes = filter_block_kses_value(
@@ -1702,10 +1704,16 @@ public function sanitize() {
17021704

17031705
if ( $original_attributes !== $filtered_attributes ) {
17041706
$serialized_attributes = serialize_block_attributes( $filtered_attributes );
1705-
$voider = WP_Block_Processor::VOID === $block_processor->get_delimiter_type() ? '/' : '';
17061707
$text = " wp:{$implicit_block_type} {$serialized_attributes} {$voider}";
1708+
} elseif ( $make_implicit ) {
1709+
$text = " wp:{$implicit_block_type} {$original_attributes} {$voider}";
17071710
}
1711+
} elseif ( $make_implicit ) {
1712+
$text = " wp:{$implicit_block_type} {$voider}";
17081713
}
1714+
} elseif ( $make_implicit ) {
1715+
// Normalize closing block delimiters too.
1716+
$text = " /wp:{$implicit_block_type} ";
17091717
}
17101718
}
17111719

0 commit comments

Comments
 (0)