Skip to content

Ensure that Mustache templates in text/plain scripts are accounted for the same as those in template tags #4446

@westonruter

Description

@westonruter

Bug Description

The following logic in \AMP_Tag_And_Attribute_Sanitizer::sanitize_disallowed_attribute_values_in_node() is lacking:

// Check the context to see if we are currently within a template tag.
// If this is the case and the attribute value contains a template placeholder, we skip sanitization.
if ( ! empty( $this->open_elements['template'] ) && preg_match( '/{{[^}]+?}}/', $attr_node->nodeValue ) ) {
continue;
}

Namely, a Mustache template can also be in a script tag that has type=text/plain and template=amp-mustache (see docs).

So anywhere that we are checking for a template tag we should also check for script with the required attributes. For example, in the form sanitizer:

$templates = $form->getElementsByTagName( 'template' );

Expected Behaviour

Mustache templates in template tags are treated the same as templates in script tags.


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

    BugSomething isn't workingP2Low prioritySanitizers

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions