-
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
Validate height, width & layout attributes #3728
Conversation
43bedcd
to
c87efb5
Compare
b93e85e
to
8666ad5
Compare
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.
Something important needing to be done here is conversion of HTML dimensions to AMP layout where necessary. One example of this which was done before is #2776 where width=100%
gets converted into layout=fixed-height
and width=auto
. Another recent example of this is conversion of width=100% height=100%
to layout=fill
, per #3543 and #3295.
The conversion logic should perhaps be performed in AMP_Base_Sanitizer::set_layout()
which should then be used by all sanitizers, and the validation can be done by AMP_Tag_And_Attribute_Sanitizer
.
With the introduction of layout validation, this redundant/obsolete logic should get removed: amp-wp/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php Lines 536 to 545 in be67818
|
That would still be needed when This is needed to make sure the layout attributes are allowed:
And this is to ensure that the defined layout is supported by the element: amp-wp/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php Lines 540 to 542 in a782d7e
|
18c0833
to
8a2b94d
Compare
8a2b94d
to
4a0a0ac
Compare
@pierlon Please make sure that this scenario is accounted for as reported at https://wordpress.org/support/topic/invalid-layout-specified-by-its-attributes-height/ Namely, code like this: <div class="embed-vidweb"><iframe id="NATCOM_iframe" src="//vidweb.com/embedcfg/izmqP6DO9n/&idioma=ES&producto=FYI&p=40932" width="100%" height="100%" frameborder="0" scrolling="no" allowfullscreen="allowfullscreen"></iframe></div> When an --- a/includes/sanitizers/class-amp-base-sanitizer.php
+++ b/includes/sanitizers/class-amp-base-sanitizer.php
@@ -304,8 +304,7 @@ abstract class AMP_Base_Sanitizer {
}
// Apply fill layout if width & height are 100%.
- if ( isset( $styles['position'], $attributes['width'], $attributes['height'] )
- && 'absolute' === $styles['position']
+ if ( isset( $attributes['width'], $attributes['height'] )
&& '100%' === $attributes['width']
&& '100%' === $attributes['height']
) {
@@ -321,7 +320,10 @@ abstract class AMP_Base_Sanitizer {
$attributes['height'] = self::FALLBACK_HEIGHT;
}
- if ( empty( $attributes['width'] ) || '100%' === $attributes['width'] ) {
+ if ( isset( $attributes['width'], $attributes['height'] ) && '100%' === $attributes['width'] && '100%' === $attributes['height'] ) {
+ $attributes['layout'] = 'fill';
+ unset( $attributes['width'], $attributes['height'] );
+ } elseif ( empty( $attributes['width'] ) || '100%' === $attributes['width'] ) {
$attributes['layout'] = 'fixed-height';
$attributes['width'] = 'auto';
} |
The layout sanitizer wasn't accounting for the dimensions being in |
0880f33
to
a85af72
Compare
That's already accounted for 😄. I also accounted for the dimensions being defined within the inline style in a85af72. |
e3efc98
to
6a6ab8c
Compare
Note: Test failure should be fixed if pulling latest changes from |
55b5ce6
to
2c3bfe5
Compare
|
@pierlon Now that I've pushed to this branch, please refrain from rebasing as it will cause headaches. |
* Improve method name. * Add test for Facebook embed that has supplied height. * Improve phpdoc.
This PR has dragged on long enough. Great work here. Let's get it into testing to shake out any bugs or things we didn't account for. |
@schlessera Please advise whether there are outstanding issues you wanted addressed with this PR prior to merging. |
@westonruter any timeline when this will be released? |
Summary
As noted by @westonruter, there are no constraints on the width and height attributes as defined in the Validator protoascii, as the conditional logic is not feasible for the protoascii format.
This PR extends the method
AMP_Tag_And_Attribute_Sanitizer::sanitize_disallowed_attribute_values_in_node
so that the logic for the supported layouts of a given element are considered, and constraints for the width and height attributes are applied not only according to the layout, but also if a layout is not given.The logic for validating these attributes is adapted from validator.js of the amproject/amphtml repository.
Video Cover Block
This PR also fixes the Cover Block when a video is selected as the background; the video in a Cover Block is filtered to get the
fill
layout and to have acover
object fit.Todo:
Fixes #2146.
Checklist