-
Notifications
You must be signed in to change notification settings - Fork 383
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
Mustache templates for tables using script[type=text/plain] are corrupted #4254
Comments
Actually, it only works on origin. The Google AMP Cache and the AMP Optimizer both strip out the HTML comments. See ampproject/amphtml#26656. |
Weston's Steps To Reproduce should be good for testing instructions. |
Bug is present with plugin version 1.5 (1.5.0 and 1.5.1). |
Bizzare. We did fix this. But I'm not seeing it now. |
@spasibych Here’s a 1.5.2-RC1 pre-release build with the fix for you to test: amp.zip (v1.5.2-RC1-20200403T193031Z-3102c5dea) |
We've just published the 1.5.2 release to WordPress.org: https://wordpress.org/plugins/amp/ You can update now via the WordPress admin. Release notes: https://github.com/ampproject/amp-wp/releases/tag/1.5.2 |
@westonruter now everything is fine, thank you very much! |
Bug Description
As reported on a support forum topic by @spasibych, a workaround for Mustache templates for tables is broken by the DOM parser in the AMP plugin.
Please refer to the amp.dev docs on Mustache templates for tables.
In particular, given this input:
The AMP plugin is outputting this as:
However, the use of a
script
to contain the template is one of the workarounds mentioned:It turns out that that the HTML comment workaround does work. Given this input:
The AMP plugin makes no modifications in the output.
Expected Behaviour
The mustache template for a table using the
<script type="text/plain">
workaround should work.Steps to reproduce
<script type="text/plain" template="amp-mustache">...</script>
element.Screenshots
Additional context
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Implementation brief
As noted in ampproject/amphtml#26656 (comment):
We'll have to figure out some other mechanism to workaround libxml failing to parse the HTML. Something that comes to mind is doing a search/replace to convert
<script type="text/plain" template="amp-mustache">
into some other element (e.g.tmp-script
) during parsing, and then replace that placeholder with the originalscript
once the DOM has been constructed.This turns out to work: https://3v4l.org/0qq5S
Note the regex for doing the search/replace will need to be hardened, in particular the regex for matching the attributes (in any order).
The logic should go into the
Document
class and called similarly to themaybe_replace_noscript_elements
method:amp-wp/src/Dom/Document.php
Lines 602 to 639 in ea28148
Note that this replacement must be done immediately after parsing, since the
Document
will then need to have thescript
replaced to successfully go through the sanitizers.QA testing instructions
Demo
Changelog entry
The text was updated successfully, but these errors were encountered: