-
Notifications
You must be signed in to change notification settings - Fork 382
HTML fragment responses are erroneously converted into incomplete AMP documents #1778
Description
Update from @westonruter:
I've created a sample plugin that can be used to easily reproduce the issue: https://gist.github.com/westonruter/ca17e51c1fe7fe25efc95f04e98b3fbc
After activating the plugin and enabling native/paired mode, going to a URL such as https://example.com/?test_fragment& will show:
The problems with this are:
- An HTML fragment is converted into an HTML document, unexpectedly.
- The character encoding is all messed up. Potentially because it lacked a
<meta charset=utf-8>to begin with. - The resulting AMP document is not even valid. This is likely due to the lack of the
wp_headaction not being run.
We should at the very least prevent starting the post-processor when the response does not contain <html. This can be done by extending the logic here:
amp-wp/includes/class-amp-theme-support.php
Lines 1522 to 1530 in c92e129
| /* | |
| * Check if the response starts with HTML markup. | |
| * Without this check, JSON responses will be erroneously corrupted, | |
| * being wrapped in HTML documents. | |
| */ | |
| if ( '<' !== substr( ltrim( $response ), 0, 1 ) ) { | |
| return $response; | |
| } |
However, we also need to validate the other two points to see if there isn't some bug to fix.
Original description is as follows.
Hello there
I'm using your plugin. There is nothing wrong. But I see a character error in the search bar on the main page. In fact, everything was good for a few days. I didn't understand why.
When you put your plugin inactive, everything returns to normal. I've looked at the link below, but there are already these codes.
amp-wp/includes/class-amp-theme-support.php
Line 192 in e60cb15
| // @todo Add character conversion. |
Example
https://www.odevbul.org (search pls)

