-
Notifications
You must be signed in to change notification settings - Fork 382
Description
Bug Description
As noted in a support topic, when a byte order mark (BOM) is present in a theme/plugin PHP file, it is prepended to the JSON that is output which then causes the AMP plugin to throw a response_not_json error since the response does not start with {. The user sees this error message:
The plugin should be more forgiving about the presence of the BOM as well as other leading whitespace.
Additionally, some caching plugins append an HTML comment to the end of the response, for example LiteSpeed Cache (litespeedtech/lscache_wp#212). This also breaks JSON parsing. So any HTML comments that are appended to the response should also be stripped prior to JSON parsing.
Expected Behaviour
Validation responses that have a leading BOM or whitespace, or trailing HTML comment, should all be stripped prior to JSON parsing.
Steps to reproduce
Activate this plugin:
<?php
/**
* Plugin Name: Add BOM and HTML Comment to End
*/
add_action(
'init',
function () {
echo "\xEF\xBB\xBF ";
}
);
add_action( 'shutdown', function () {
if ( did_action( 'wp_footer' ) ) {
echo "<!-- Generated by me! -->";
}
} );Then try to validate a page.
Do not alter or remove anything below. The following sections will be managed by moderators only.
