-
Notifications
You must be signed in to change notification settings - Fork 384
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
AMP_Content_Sanitizer::sanitize() strips out amp-bind Bindings #836
Comments
I can confirm this is indeed a problem. Here's a standalone test case that shows the problem with parsing: <?php
$dom = new DOMDocument();
$test_html = '<p id="test-stripping-amp-bind" [text]="foo">test</p>' . PHP_EOL;
$test_html .= "<button on=\"tap:AMP.setState({foo: 'amp-bind'})\">Set to amp-bind</button>\n";
$dom->loadHTML( sprintf( '<!doctype html><html amp><head><meta charset="utf-8"></head><body>%s</body></html>', PHP_EOL . $test_html ) );
echo $dom->saveHTML(); The result is this:
<!DOCTYPE html>
<html amp><head><meta charset="utf-8"></head><body>
<p id="test-stripping-amp-bind">test</p>
<button on="tap:AMP.setState({foo: 'amp-bind'})">Set to amp-bind</button>
</body></html> The binding attribute The only thing I can think of is to do a global replacement of such attributes before parsing to take the form of |
I have a similar problem: I load html-content via xhr through amp-script and form into div xhrcontent.
|
@jdalk Please open a new issue and provide the code you are using the generate AMP markup, and the full code you are using to fetch it. |
I've made some template files which run through a loop to pull in data from Child Posts which then runs
AMP_Content_Sanitizer::sanitize()
on the Post Content of each item that is pulled in.The Post Content of the pulled in Posts (When viewed in AMP) utilizes amp-bind to toggle a Hidden state on elements. However, I noticed that when the DOMDocument Object is created from the passed in
$content
as part ofAMP_DOM_Utils::get_dom_from_content()
, it ignores any of the specialamp-bind
Binding attributes. This is presumably due to PHP not recognizing them as valid and throwing them out.This only effects cases where
amp-bind
Binding attributes are being ran through the Sanitization method directly. If it simply exists in the template file (Therefore not sanitized in the same way Post Content is) it does not affect it.This primarily is an issue in cases where you are wanting a Shortcode to still function similarly when viewed on an AMP version of a page, such as hiding/showing/expanding/etc. different elements based on user interaction.
Reproduction steps:
Place the following code at the top of https://github.com/Automattic/amp-wp/blob/8b416f9bbdba64e07082dcc02a9b64aa34c2d270/includes/templates/class-amp-content-sanitizer.php#L22 to simulate it being a part of the Post Content:
And then the following to load in
amp-bind
:Your
<p>
tag will appear without the[text]
attribute but the<button>
will still set the AMP State correctly (Although it will not be able to do much withoutamp-bind
Bindings that use it).The text was updated successfully, but these errors were encountered: