Make WordPress Core


Ignore:
Timestamp:
05/16/2023 02:43:46 PM (19 months ago)
Author:
audrasjb
Message:

Editor: Ensure block comments are of a valid form.

Ensures that the block delimiter comments are of a valid form: opening with <!-- and closing with -->.

Props xknown, isabel_brison, peterwilsoncc.
Merges [55762] to branch 6.2.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/6.2/src/wp-includes/blocks.php

    r55635 r55767  
    799799    $result = '';
    800800
     801    if ( false !== strpos( $text, '<!--' ) && false !== strpos( $text, '--->' ) ) {
     802        $text = preg_replace_callback( '%<!--(.*?)--->%', '_filter_block_content_callback', $text );
     803    }
     804
    801805    $blocks = parse_blocks( $text );
    802806    foreach ( $blocks as $block ) {
     
    806810
    807811    return $result;
     812}
     813
     814/**
     815 * Callback used for regular expression replacement in filter_block_content().
     816 *
     817 * @private
     818 * @since 6.2.1
     819 *
     820 * @param array $matches Array of preg_replace_callback matches.
     821 * @return string Replacement string.
     822 */
     823function _filter_block_content_callback( $matches ) {
     824    return '<!--' . rtrim( $matches[1], '-' ) . '-->';
    808825}
    809826
Note: See TracChangeset for help on using the changeset viewer.