Skip to content

Width attribute on table col elements causes validation errors #1062

@westonruter

Description

@westonruter

When post_content contains HTML such as:

<table class="auto-style1 sws_custom_table" style="width: 100%; display: table; background-color: #ffffff; border: 2px solid #eaeaea;" border="0" width="630" cellspacing="0"><colgroup> <col style="mso-width-source: userset; mso-width-alt: 8988; width: 190pt;" width="253" /> <col style="mso-width-source: userset; mso-width-alt: 6826; width: 144pt;" width="192" /> <col style="mso-width-source: userset; mso-width-alt: 8135; width: 172pt;" width="229" /></colgroup>
...</table>

This is getting converted to AMP as:

<table class="auto-style1 sws_custom_table amp-wp-inline-976a106f7543a9a2e8e3c8a97560be03" width="630"><colgroup><col width="253" class="amp-wp-inline-16106abec734b745f40158cc486aa0fe"/><col width="192" class="amp-wp-inline-91e2d2d529220418b62e99acb85f0928"/><col width="229" class="amp-wp-inline-43ca072c586bb2eaad4c6de773864f95"/></colgroup>
...</table>

This results in a validation error:

DISALLOWED_HTML: The attribute 'width' may not appear in tag 'col'.

First of all, maybe it is a bug in AMP that this attribute is not allowed. We should double check that first.

Otherwise, if it is really not allowed, then whitelist sanitizer may be incorrectly merging the width layout attribute among the attributes allowed on an element:

https://github.com/Automattic/amp-wp/blob/4e1cd227b10f2fcd6add44a24b078158aad41e53/includes/sanitizers/class-amp-allowed-tags-generated.php#L10573

See here:

https://github.com/Automattic/amp-wp/blob/4e1cd227b10f2fcd6add44a24b078158aad41e53/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php#L1468

layout_allowed_attributes is not globally-allowed it seems. Maybe that condition needs to be removed.

As reported on https://wordpress.org/support/topic/not-a-valid-amp-page-7/

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions