Skip to content

Add support for also_requires_attr validator constraint #4447

@westonruter

Description

@westonruter

Feature description

AMP requires that any element with an on event handler attribute also have a tabindex and a role=button. Currently, however, you can create AMP content in WordPress and validation errors will leak.

Consider a Custom HTML block containing:

<span on="tap:AMP.print">Print!</span>

Two validation errors leak to the frontend:

image

The reason for this the AMP plugin does not yet support the trigger like the on attribute spec has:

  attrs: {
    name: "on"
    trigger: {
      if_value_regex: "tap:.*"
      also_requires_attr: "role"
      also_requires_attr: "tabindex"
    }
  }

There are currently 22 instances of trigger in the protoascii, and each one is for also_requires_attr. This is currently called out as a todo:

* @todo Need to check the following items that are not yet checked by this sanitizer:
*
* - `also_requires_attr` - if one attribute is present, this requires another.
* - `ChildTagSpec` - Places restrictions on the number and type of child tags.
* - `if_value_regex` - if one attribute value matches, this places a restriction
* on another attribute/value.

The tag-and-attribute sanitizer needs to be updated to support this constraint. This will include updating the Python spec parser to extract these values. When a failure is encountered a new validation error code should be raised. (Currently it is UNKNOWN in the AMP validator but we can do something specific.)


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

Implementation brief

QA testing instructions

Demo

Changelog entry

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Low priorityValidationWS:CoreWork stream for Plugin core

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions