Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Byte order mark (BOM) breaks ability to do validation #4678

Closed
westonruter opened this issue May 10, 2020 · 0 comments · Fixed by #4683 or #4679
Closed

Byte order mark (BOM) breaks ability to do validation #4678

westonruter opened this issue May 10, 2020 · 0 comments · Fixed by #4683 or #4679
Labels
Bug Something isn't working Developer Tools
Milestone

Comments

@westonruter
Copy link
Member

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:

URL validation failed due to the AMP validation request not returning JSON data. This may be due to a PHP fatal error occurring. Please check your server PHP error logs; to do this you may need to enable WP_DEBUG_LOG. If you are stuck, please search the support forum for possible related topics, or otherwise start a new support topic including the error message, the URL to your site, and your active theme/plugins. Please include your Site Health Info.

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.

Acceptance criteria

Implementation brief

QA testing instructions

Demo

Changelog entry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Developer Tools
Projects
None yet
2 participants