Skip to content

Commit

Permalink
Update error messages html comment placeholders with mustache tags
Browse files Browse the repository at this point in the history
* HTML comment placeholders get stripped by HTML minifiers.
  • Loading branch information
thelovekesh committed Mar 2, 2022
1 parent ad09837 commit da9321a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
4 changes: 2 additions & 2 deletions wp-admin/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
case 'offline':
$title_prefix = __( 'Offline', 'pwa' );
$content = sprintf( '<h1>%s</h1>', esc_html__( 'Offline', 'pwa' ) );
$content .= '<p><!--WP_SERVICE_WORKER_ERROR_MESSAGE--></p>';
$content .= '<p>{{{WP_SERVICE_WORKER_ERROR_MESSAGE}}}</p>'; // phpcs:ignore WordPressVIPMinimum.Security.Mustache.OutputNotation -- Prints error message placeholder.
$content .= sprintf( '<p>%s</p>', 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( '<h1>%s</h1>', esc_html__( 'A server error occurred.', 'pwa' ) );
$content .= '<p><!--WP_SERVICE_WORKER_ERROR_MESSAGE--></p>';
$content .= '<p>{{{WP_SERVICE_WORKER_ERROR_MESSAGE}}}</p>'; // phpcs:ignore WordPressVIPMinimum.Security.Mustache.OutputNotation -- Prints error message placeholder.
$content .= sprintf(
'<p>%s</p>',
esc_html__( 'Something went wrong which prevented WordPress from serving a response. Please check your error logs.', 'pwa' )
Expand Down
12 changes: 5 additions & 7 deletions wp-includes/js/service-worker-navigation-routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions wp-includes/js/service-worker-offline-commenting.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
};

let body = text.replace(
/[<]!--WP_SERVICE_WORKER_ERROR_MESSAGE-->/,
'{{{WP_SERVICE_WORKER_ERROR_MESSAGE}}}',
errorMessages.error
);
body = body.replace(
Expand Down Expand Up @@ -125,7 +125,7 @@
};

const body = text.replace(
/[<]!--WP_SERVICE_WORKER_ERROR_MESSAGE-->/,
'{{{WP_SERVICE_WORKER_ERROR_MESSAGE}}}',
errorMessages.comment
);

Expand Down
6 changes: 3 additions & 3 deletions wp-includes/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,16 @@ function wp_service_worker_error_details_template( $output = '' ) {
if ( empty( $output ) ) {
$output = '<details id="error-details"><summary>' . esc_html__( 'More Details', 'pwa' ) . '</summary>{{{error_details_iframe}}}</details>'; // phpcs:ignore WordPressVIPMinimum.Security.Mustache.OutputNotation -- Variable includes iframe tag.
}
echo '<!--WP_SERVICE_WORKER_ERROR_TEMPLATE_BEGIN-->';
echo '{{{WP_SERVICE_WORKER_ERROR_TEMPLATE_BEGIN}}}'; // phpcs:ignore WordPressVIPMinimum.Security.Mustache.OutputNotation -- Prints template begin tag.
echo wp_kses_post( $output );
echo '<!--WP_SERVICE_WORKER_ERROR_TEMPLATE_END-->';
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 '<p><!--WP_SERVICE_WORKER_ERROR_MESSAGE--></p>';
echo '<p>{{{WP_SERVICE_WORKER_ERROR_MESSAGE}}}</p>'; // phpcs:ignore WordPressVIPMinimum.Security.Mustache.OutputNotation -- Prints error message placeholder.
}

/**
Expand Down

0 comments on commit da9321a

Please sign in to comment.