From da9321a1ed8bf3815532d498bddc17644e98df82 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Wed, 2 Mar 2022 20:57:39 +0530 Subject: [PATCH] Update error messages html comment placeholders with mustache tags * HTML comment placeholders get stripped by HTML minifiers. --- wp-admin/error.php | 4 ++-- wp-includes/js/service-worker-navigation-routing.js | 12 +++++------- wp-includes/js/service-worker-offline-commenting.js | 4 ++-- wp-includes/template.php | 6 +++--- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/wp-admin/error.php b/wp-admin/error.php index 59c9c3aea..1aed72792 100644 --- a/wp-admin/error.php +++ b/wp-admin/error.php @@ -16,13 +16,13 @@ case 'offline': $title_prefix = __( 'Offline', 'pwa' ); $content = sprintf( '

%s

', esc_html__( 'Offline', 'pwa' ) ); - $content .= '

'; + $content .= '

{{{WP_SERVICE_WORKER_ERROR_MESSAGE}}}

'; // phpcs:ignore WordPressVIPMinimum.Security.Mustache.OutputNotation -- Prints error message placeholder. $content .= sprintf( '

%s

', esc_html__( 'In the future, this error screen could provide you with actions you can perform while offline, like edit recent drafts in Gutenberg.', 'pwa' ) ); break; case '500': $title_prefix = __( 'Internal Server Error', 'pwa' ); $content = sprintf( '

%s

', esc_html__( 'A server error occurred.', 'pwa' ) ); - $content .= '

'; + $content .= '

{{{WP_SERVICE_WORKER_ERROR_MESSAGE}}}

'; // phpcs:ignore WordPressVIPMinimum.Security.Mustache.OutputNotation -- Prints error message placeholder. $content .= sprintf( '

%s

', esc_html__( 'Something went wrong which prevented WordPress from serving a response. Please check your error logs.', 'pwa' ) diff --git a/wp-includes/js/service-worker-navigation-routing.js b/wp-includes/js/service-worker-navigation-routing.js index 96a4295e7..0c46a7902 100644 --- a/wp-includes/js/service-worker-navigation-routing.js +++ b/wp-includes/js/service-worker-navigation-routing.js @@ -68,11 +68,11 @@ ERROR_OFFLINE_URL, ERROR_500_URL, NAVIGATION_DENYLIST_PATTERNS, ERROR_MESSAGES * }; let body = text.replace( - /[<]!--WP_SERVICE_WORKER_ERROR_MESSAGE-->/, + '{{{WP_SERVICE_WORKER_ERROR_MESSAGE}}}', errorMessages.error ); body = body.replace( - /([<]!--WP_SERVICE_WORKER_ERROR_TEMPLATE_BEGIN-->)((?:.|\n)+?)([<]!--WP_SERVICE_WORKER_ERROR_TEMPLATE_END-->)/, + /({{{WP_SERVICE_WORKER_ERROR_TEMPLATE_BEGIN}}})((?:.|\n)+?)({{{WP_SERVICE_WORKER_ERROR_TEMPLATE_END}}})/, (details) => { if (!responseBody) { return ''; // Remove the details from the document entirely. @@ -103,13 +103,11 @@ ERROR_OFFLINE_URL, ERROR_500_URL, NAVIGATION_DENYLIST_PATTERNS, ERROR_MESSAGES * // Replace the comments. details = details.replace( - '<' + - '!--WP_SERVICE_WORKER_ERROR_TEMPLATE_BEGIN-->', + '{{{WP_SERVICE_WORKER_ERROR_TEMPLATE_BEGIN}}}', '' ); details = details.replace( - '<' + - '!--WP_SERVICE_WORKER_ERROR_TEMPLATE_END-->', + '{{{WP_SERVICE_WORKER_ERROR_TEMPLATE_END}}}', '' ); return details; @@ -137,7 +135,7 @@ ERROR_OFFLINE_URL, ERROR_500_URL, NAVIGATION_DENYLIST_PATTERNS, ERROR_MESSAGES * }; const body = text.replace( - /[<]!--WP_SERVICE_WORKER_ERROR_MESSAGE-->/, + '{{{WP_SERVICE_WORKER_ERROR_MESSAGE}}}', navigator.onLine ? errorMessages.serverOffline : errorMessages.clientOffline diff --git a/wp-includes/js/service-worker-offline-commenting.js b/wp-includes/js/service-worker-offline-commenting.js index b605e2573..39bda2a46 100644 --- a/wp-includes/js/service-worker-offline-commenting.js +++ b/wp-includes/js/service-worker-offline-commenting.js @@ -36,7 +36,7 @@ }; let body = text.replace( - /[<]!--WP_SERVICE_WORKER_ERROR_MESSAGE-->/, + '{{{WP_SERVICE_WORKER_ERROR_MESSAGE}}}', errorMessages.error ); body = body.replace( @@ -125,7 +125,7 @@ }; const body = text.replace( - /[<]!--WP_SERVICE_WORKER_ERROR_MESSAGE-->/, + '{{{WP_SERVICE_WORKER_ERROR_MESSAGE}}}', errorMessages.comment ); diff --git a/wp-includes/template.php b/wp-includes/template.php index afeab63be..1603c856f 100644 --- a/wp-includes/template.php +++ b/wp-includes/template.php @@ -160,16 +160,16 @@ function wp_service_worker_error_details_template( $output = '' ) { if ( empty( $output ) ) { $output = '
' . esc_html__( 'More Details', 'pwa' ) . '{{{error_details_iframe}}}
'; // phpcs:ignore WordPressVIPMinimum.Security.Mustache.OutputNotation -- Variable includes iframe tag. } - echo ''; + echo '{{{WP_SERVICE_WORKER_ERROR_TEMPLATE_BEGIN}}}'; // phpcs:ignore WordPressVIPMinimum.Security.Mustache.OutputNotation -- Prints template begin tag. echo wp_kses_post( $output ); - echo ''; + echo '{{{WP_SERVICE_WORKER_ERROR_TEMPLATE_END}}}'; // phpcs:ignore WordPressVIPMinimum.Security.Mustache.OutputNotation -- Prints template end tag. } /** * Display service worker error message template tag. */ function wp_service_worker_error_message_placeholder() { - echo '

'; + echo '

{{{WP_SERVICE_WORKER_ERROR_MESSAGE}}}

'; // phpcs:ignore WordPressVIPMinimum.Security.Mustache.OutputNotation -- Prints error message placeholder. } /**