Make WordPress Core

Changeset 55762


Ignore:
Timestamp:
05/16/2023 02:21:35 PM (11 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.

File:
1 edited

Legend:

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

    r55703 r55762  
    801801    $result = '';
    802802
     803    if ( false !== strpos( $text, '<!--' ) && false !== strpos( $text, '--->' ) ) {
     804        $text = preg_replace_callback( '%<!--(.*?)--->%', '_filter_block_content_callback', $text );
     805    }
     806
    803807    $blocks = parse_blocks( $text );
    804808    foreach ( $blocks as $block ) {
     
    808812
    809813    return $result;
     814}
     815
     816/**
     817 * Callback used for regular expression replacement in filter_block_content().
     818 *
     819 * @private
     820 * @since 6.2.1
     821 *
     822 * @param array $matches Array of preg_replace_callback matches.
     823 * @return string Replacement string.
     824 */
     825function _filter_block_content_callback( $matches ) {
     826    return '<!--' . rtrim( $matches[1], '-' ) . '-->';
    810827}
    811828
Note: See TracChangeset for help on using the changeset viewer.