Skip to content
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

Fix dispatch_key handling for NAME_VALUE_DISPATCH; add cdata validation #926

Merged
merged 5 commits into from
Feb 4, 2018

Conversation

westonruter
Copy link
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
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
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
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.

@@ -88,6 +88,13 @@ public function collect_style_elements() {
continue;
}

if ( 'body' === $style_element->parentNode->nodeName && $style_element->hasAttribute( 'amp-keyframes' ) ) {
$validity = $this->validate_amp_keyframe( $style_element );
Copy link
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
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
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.

None yet

2 participants