-
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
Introduce Bento sanitizer to handle with bento
-prefixed components
#6722
Conversation
bento
-prefixed components
|
|
7167dc2
to
7f44f94
Compare
7f44f94
to
810b25f
Compare
810b25f
to
e13cc99
Compare
* Fix exempting non-AMP Bento stylesheet * Ensure scripts are removed if no Bento components present * Prefer bento when any Bento component is discovered (not just when conversion happened)
Plugin builds for 58139b2 are ready 🛎️!
|
Codecov Report
@@ Coverage Diff @@
## develop #6722 +/- ##
=============================================
+ Coverage 77.00% 77.03% +0.03%
- Complexity 6548 6577 +29
=============================================
Files 264 265 +1
Lines 20901 20988 +87
=============================================
+ Hits 16095 16169 +74
- Misses 4806 4819 +13
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went through the code and left a few minor comments.
I didn't get a chance to test it out locally, but will do so on Monday.
Co-authored-by: Piotr Delawski <[email protected]>
I've tested the code locally. The provided sample code displaying an accordion works as expected. I also tried adding some <script type="module" src="https://cdn.ampproject.org/bento.mjs" crossorigin="anonymous"></script>
<script nomodule src="https://cdn.ampproject.org/bento.js" crossorigin="anonymous"></script>
<script type="module" src="https://cdn.ampproject.org/v0/bento-mathml-1.0.mjs" crossorigin="anonymous"></script>
<script nomodule src="https://cdn.ampproject.org/v0/bento-mathml-1.0.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.ampproject.org/v0/bento-mathml-1.0.css" crossorigin="anonymous">
<h2>The Quadratic Formula</h2>
<bento-mathml
style="height: 40px"
data-formula="\[x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\]"
></bento-mathml>
<h2>Inline formula</h2>
<p>
This is an example of a formula,
<bento-mathml
style="height: 40px; width: 147px"
inline
data-formula="\[x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\]"
></bento-mathml>
placed inline in the middle of a block of text.
</p> The AMP version doesn't render the formulas.
When I removed the inline <style>
bento-mathml {
width: 150px;
height: 40px;
}
</style> Is that expected behaviour? |
This is because the default layout then becomes Working on a fix. |
OK, this is now much more robust. |
…-js-support * 'develop' of github.com:ampproject/amp-wp: Use CF7 instead of Autoptimize for AMP-incompatible plugin in E2E tests Replace autoptimize with akismet for E2E tests Pin NodeJS to v14 to match WP core and Gutenberg Regenerate package-lock.json at lockfileVersion 1 Update Gutenberg package dependencies Update Gutenberg package dependencies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the latest changes, bento-mathml
displays correctly when there is no inline style
attribute.
I've also tested bento-instagram
both with explicit dimensions provided in an inline style
attribute and with position: absolute; width: 100%; height: 100%
(in order to trigger a layout="fill"
). In both cases the Instagram embed rendered as expected.
Co-authored-by: Piotr Delawski <[email protected]>
All looks good, I tested few random components date-countdown, base carousel, twitter, WordPress Embed All looks good except base carousel here is what I tried <script type="module" src="https://cdn.ampproject.org/bento.mjs" crossorigin="anonymous"></script>
<script nomodule="" src="https://cdn.ampproject.org/bento.js" crossorigin="anonymous"></script>
<script type="module" src="https://cdn.ampproject.org/v0/bento-base-carousel-1.0.mjs" crossorigin="anonymous"></script>
<script nomodule="" src="https://cdn.ampproject.org/v0/bento-base-carousel-1.0.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.ampproject.org/v0/bento-base-carousel-1.0.css" crossorigin="anonymous">
<bento-base-carousel id="my-carousel">
<div class="red"></div>
<div class="blue"></div>
<div class="green"></div>
</bento-base-carousel> CSS for it you can add it Customizer bento-base-carousel,
bento-base-carousel > div {
aspect-ratio: 4/1;
}
.red {
background: darkred;
}
.blue {
background: steelblue;
}
.green {
background: seagreen;
} This won't show unless you add layout for it, it does support all layouts |
@milindmore22 Yes, this is somewhat of a known limitation. In order for that amp-wp/tests/php/test-amp-bento-sanitizer.php Line 223 in 1d435a2
is converted to: amp-wp/tests/php/test-amp-bento-sanitizer.php Line 255 in 1d435a2
|
…-js-support * 'develop' of github.com:ampproject/amp-wp: (45 commits) Update Gutenberg package dependencies Update CODEOWNERS Update amphtml spec to 2111242025000 Stop mapping E2E test plugins dir to container volume Add demo plugin ZIP archive Fix script command Fix lint issues Ensure React state updates are not performed on unmounted components Use different Jest configs for E2E tests; use `.env` config file Refactor "Other Settings" E2E tests Ensure selector is available before scrolling element into view Use more robust internal activate/deactivate functions in E2E tests Introduce general `saveSettings` util function for E2E tests Remove unnecessary cleanup functions in E2E tests Install Hestia theme globally as it is used in multiple tests Use local demo plugin in E2E tests Ensure disabled back button is covered by E2E tests Add `SiteScanContextProvider` mock to prevent unit test errors Ensure Site Scan progress bar never goes backwards Prevent going back in Wizard if Site Scan is in progress ...
QA Passed Everything looks good 👍🏼 ✅ Bento components are renamed to the AMP components. |
Summary
Bento components will be available not only as
amp
-prefixed components, but also with thebento
prefix. Consider this following example which can be pasted into a Custom HTML block on a site without the AMP plugin running at all:On a non-AMP page, this is output as expected:
However, when viewing the AMP page it completely breaks:
Validating the page shows that there are many errors detected, resulting in the
bento-accordion
and Bento stylesheet and scripts being removed:At the moment, all of the Bento components are just aliases for corresponding v1.0 AMP components. Therefore, in order to seamlessly incorporate Bento components into valid AMP pages, what is needed is to rename the
bento
prefix toamp
when there is a corresponding component available. So there is anbento-accordion
component and a correspondingamp-accordion
v1.0 which is also the Bento version, as opposed to v0.1 which is the classic version. So we can just renamebento-accordion
toamp-accordion
which will ensure that it is recognized as valid AMP markup and thus won't be sanitized from the page. Any CSS selectors referencingbento-accordion
are also updated to useamp-accordion
. When such a conversion is done, any Bento-specific stylesheets and scripts can also be removed from the document since the auto-extension importing AMP will then automatically add the required markup.So the above HTML is converted into the following on a valid AMP page:
This PR also accounts for future Bento components which do not have AMP aliases. When such a component is encountered, the component along with its dependent scripts and stylesheet will not marked with
data-px-verified
so that the plugin's sanitizer will not later strip it out. Such pages with non-AMP Bento components will not be be marked asamp
pages as they are not valid AMP, although they will still incorporate the AMP runtime and will go through the AMP Optimizer. This is the “Moderate” sandboxing level introduced in #6443.Fix handling of ID attributes during sanitizer conversion
In 263501f I worked around Unexpected Handling of Element IDs in PHP DOM. In short, it turns out that PHP DOM does not handle element IDs the same way as browser DOM does. Therefore, in order to element conversions successfully, it's important to remove the
id
attribute from the old element before adding it to the new element.Fix JS error on Validated URL screen when there are no Validation Errors
I discovered on the Validated URL screen that the rows wouldn't expand in the Stylesheets metabox. Looking at the console I saw an error coming from:
amp-wp/assets/src/amp-validation/amp-validated-url-post-edit-screen.js
Line 278 in 5405daa
This is for this search box:
The issue is that when there are no Validation Errors, then no search box is added to the page:
And this causes an error. Fixed in e13cc99.
Checklist