From bbaaae817af6ed600572b3ff7238db63555cc508 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 14 Jan 2022 11:14:56 +0000 Subject: [PATCH] Late escape latest comments block (#37865) * Initial pass * Escape comment excerpt * Escape comment post title * Escape author name * Revert escaping of translations * Move Post title escaping at point of output Previously we were esaping within the function generating the title. Now we escape the result of calling the function. * Revert escaping of hardcoded inlined string The key here is that they are inlined and not variables * Revert escape of comment excerpt This is not escaped when used in Core so is ok * Revert escaping get_block_wrapper_attributes --- packages/block-library/src/latest-comments/index.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/block-library/src/latest-comments/index.php b/packages/block-library/src/latest-comments/index.php index 3e649bbf5f749..1b340f39fe70f 100644 --- a/packages/block-library/src/latest-comments/index.php +++ b/packages/block-library/src/latest-comments/index.php @@ -30,7 +30,7 @@ function wp_latest_comments_draft_or_post_title( $post = 0 ) { if ( empty( $title ) ) { $title = __( '(no title)' ); } - return esc_html( $title ); + return $title; } /** @@ -86,14 +86,14 @@ function render_block_core_latest_comments( $attributes = array() ) { $author_markup = ''; if ( $author_url ) { - $author_markup .= '' . get_comment_author( $comment ) . ''; + $author_markup .= '' . esc_html( get_comment_author( $comment ) ) . ''; } else { - $author_markup .= '' . get_comment_author( $comment ) . ''; + $author_markup .= '' . esc_html( get_comment_author( $comment ) ) . ''; } // `_draft_or_post_title` calls `esc_html()` so we don't need to wrap that call in // `esc_html`. - $post_title = '' . wp_latest_comments_draft_or_post_title( $comment->comment_post_ID ) . ''; + $post_title = '' . esc_html( wp_latest_comments_draft_or_post_title( $comment->comment_post_ID ) ) . ''; $list_items_markup .= sprintf( /* translators: 1: author name (inside or tag, based on if they have a URL), 2: post title related to this comment */ @@ -106,7 +106,7 @@ function render_block_core_latest_comments( $attributes = array() ) { $list_items_markup .= sprintf( '', esc_attr( get_comment_date( 'c', $comment ) ), - date_i18n( get_option( 'date_format' ), get_comment_date( 'U', $comment ) ) + esc_html( date_i18n( get_option( 'date_format' ), get_comment_date( 'U', $comment ) ) ) ); } $list_items_markup .= '';