Skip to content

Fix dispatch_key handling for NAME_VALUE_DISPATCH; add cdata validation#926

Merged
westonruter merged 5 commits intodevelopfrom
fix/spec-dispatch-key-handling
Feb 4, 2018
Merged

Fix dispatch_key handling for NAME_VALUE_DISPATCH; add cdata validation#926
westonruter merged 5 commits intodevelopfrom
fix/spec-dispatch-key-handling

Conversation

@westonruter
Copy link
Copy Markdown
Member

@westonruter westonruter commented Feb 3, 2018

This fixes the longstanding annoyance for when the spec was read, the one value had to be removed for data-multi-size or else unit tests would fail. It turns out to be due to the dispatch_key not being supported. So this is now fixed and the list of tags and attributes can be re-generated at will.

In addition to dispatch_key being included in the generated PHP file, so too cdata is now included, with validation for blacklisted regex and amp-keyframes styles. This is needed for validating elements in the head. See #926.

@westonruter westonruter added this to the v0.7 milestone Feb 3, 2018
Copy link
Copy Markdown
Collaborator

@ThierryA ThierryA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @westonruter, I added minor comments but this is good to go.

* @return true|WP_Error Validity.
*/
private function validate_amp_keyframe( $style ) {
if ( strlen( $style->textContent ) > 500000 ) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better to store 500000 in constant.

* https://github.com/ampproject/amphtml/blob/eda1daa8c40f830207edc8d8088332b32a15c1a4/validator/validator.proto#L111-L120
*/

// Indicates that the attribute does not form a dispatch key.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to add valid PHPDoc with @SInCE tags for these constances.

}

if ( 'body' === $style_element->parentNode->nodeName && $style_element->hasAttribute( 'amp-keyframes' ) ) {
$validity = $this->validate_amp_keyframe( $style_element );
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this doesn't really have to be stored in a var and could part of the conditional statement above.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason behind is is that in #912 we need to add reporting and $validity is a WP_Error instance, so we'd want to report it when this is merged into that PR.

@westonruter
Copy link
Copy Markdown
Member Author

Thanks, I'll address these in the next PR.

@westonruter westonruter merged commit f2c38bd into develop Feb 4, 2018
@westonruter westonruter deleted the fix/spec-dispatch-key-handling branch February 4, 2018 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants