Skip to content

HTML fragment responses are erroneously converted into incomplete AMP documents #1778

@tryazi

Description

@tryazi

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&amp will show:

image

The problems with this are:

  1. An HTML fragment is converted into an HTML document, unexpectedly.
  2. The character encoding is all messed up. Potentially because it lacked a <meta charset=utf-8> to begin with.
  3. The resulting AMP document is not even valid. This is likely due to the lack of the wp_head action 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:

/*
* 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.

// @todo Add character conversion.

Example
https://www.odevbul.org (search pls)
karakter

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions