Skip to content

Commit

Permalink
Validator roll-up (#21507)
Browse files Browse the repository at this point in the history
 - cl/239414441 Revision bump for #21463
 - cl/239234304 Add deprecation warning for manufactured body caused by non-ASCII whitespace.
 - cl/239228383 Explicitly disallow `<template>` outside the document `<body>`.
 - cl/239220081 Add a feature test case for a non-amp document.
 - cl/239050986 Revision bump for #21459
 - cl/239048160 Fix corner case of ancestor marker tracking.
 - cl/238487968 Revision bump for #21107
 - cl/238483735 Revision bump for #21264
  • Loading branch information
honeybadgerdontcare authored and Gregable committed Mar 20, 2019
1 parent e16e216 commit a5f911e
Show file tree
Hide file tree
Showing 18 changed files with 213 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ amp-brid-player/0.1/test/validator-amp-brid-player.html:72:2 The tag 'amp-brid-p
| width="480" height="270">
| </amp-brid-player>
| </body>
| </html>
| </html>
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ tags: { # <amp-brid-player>
tag_name: "AMP-BRID-PLAYER"
requires_extension: "amp-brid-player"
attrs: { name: "autoplay" }
attrs: {
name: "data-dynamic"
value_regex: "[a-z]+"
}
attrs: {
name: "data-outstream"
mandatory_oneof: "['data-outstream', 'data-playlist', 'data-video']"
Expand All @@ -51,10 +55,6 @@ tags: { # <amp-brid-player>
mandatory_oneof: "['data-outstream', 'data-playlist', 'data-video']"
value_regex: ".+"
}
attrs: {
name: "data-dynamic"
value_regex: "[a-z]+"
}
attrs: {
name: "data-video"
mandatory_oneof: "['data-outstream', 'data-playlist', 'data-video']"
Expand Down
2 changes: 2 additions & 0 deletions extensions/amp-mustache/validator-amp-mustache.protoascii
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ tags: {
html_format: AMP4ADS
html_format: ACTIONS
tag_name: "TEMPLATE"
mandatory_ancestor: "BODY"
# <template> tags may not be nested inside other <template> tags.
disallowed_ancestor: "TEMPLATE"
# <templates> tags inside <amp-date-picker> have additional requirements
Expand Down Expand Up @@ -159,6 +160,7 @@ tags: {
html_format: AMP4EMAIL
tag_name: "TEMPLATE"
spec_name: "TEMPLATE (AMP4EMAIL)"
mandatory_ancestor: "BODY"
# <template> tags may not be nested inside other <template> tags.
disallowed_ancestor: "TEMPLATE (AMP4EMAIL)"
# <templates> tags inside <amp-date-picker> have additional requirements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@
<body>
<!-- Invalid: Use of autoscroll outside amp-sidebar with autoscroll-->
<div autoscroll></div>

<!-- testing with a parent that does not have a matching tag. -->
<does-not-exist>
<div autoscroll></div>
</does-not-exist>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,14 @@ FAIL
| <div autoscroll></div>
>> ^~~~~~~~~
amp-sidebar/0.1/test/validator-amp-sidebar-autoscroll-invalid.html:32:2 The attribute 'autoscroll' may not appear in tag 'div'. [DISALLOWED_HTML]
|
| <!-- testing with a parent that does not have a matching tag. -->
| <does-not-exist>
>> ^~~~~~~~~
amp-sidebar/0.1/test/validator-amp-sidebar-autoscroll-invalid.html:35:2 The tag 'does-not-exist' is disallowed. [DISALLOWED_HTML]
| <div autoscroll></div>
>> ^~~~~~~~~
amp-sidebar/0.1/test/validator-amp-sidebar-autoscroll-invalid.html:36:4 The attribute 'autoscroll' may not appear in tag 'div'. [DISALLOWED_HTML]
| </does-not-exist>
| </body>
| </html>
2 changes: 1 addition & 1 deletion extensions/amp-story/validator-amp-story.protoascii
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,11 @@ tags: {
attrs: { name: "animate-in-delay" }
attrs: { name: "animate-in-duration" }
attrs: { name: "animate-in-timing-function" }
attrs: { name: "grid-area" }
attrs: {
name: "interactive"
value: ""
}
attrs: { name: "grid-area" }
attrs: {
name: "scale-end"
value_regex: "[0-9]+([.][0-9]+)?"
Expand Down
54 changes: 42 additions & 12 deletions validator/engine/htmlparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,28 @@ class TagNameStack {
* @param {string} text
*/
pcdata(text) {
if (!amp.htmlparser.HtmlParser.SPACE_RE_.test(text)) {
if (amp.htmlparser.HtmlParser.SPACE_RE_.test(text)) {
// Only ASCII whitespace; this can be ignored for validator's purposes.
} else if (amp.htmlparser.HtmlParser.CPP_SPACE_RE_.test(text)) {
// Non-ASCII whitespace; if this occurs outside <body>, output a
// manufactured-body error. Do not create implicit tags, in order to match
// the behavior of the buggy C++ parser. (It just so happens this is also
// good UX, since the subsequent validation errors caused by the implicit
// tags are unhelpful.)
switch (this.region_) {
// Fallthroughs intentional.
case TagRegion.PRE_DOCTYPE:
case TagRegion.PRE_HTML:
case TagRegion.PRE_HEAD:
case TagRegion.IN_HEAD:
case TagRegion.PRE_BODY:
if (this.handler_.markManufacturedBody) {
this.handler_.markManufacturedBody();
}
}
} else {
// Non-whitespace text; if this occurs outside <body>, output a
// manufactured-body error and create the necessary implicit tags.
switch (this.region_) {
// Fallthroughs intentional.
case TagRegion.PRE_DOCTYPE: // doctype is not manufactured
Expand All @@ -402,11 +423,10 @@ class TagNameStack {
case TagRegion.IN_HEAD:
this.endTag(new amp.htmlparser.ParsedHtmlTag('HEAD'));
case TagRegion.PRE_BODY:
if (this.handler_.markManufacturedBody)
{this.handler_.markManufacturedBody();}
if (this.handler_.markManufacturedBody) {
this.handler_.markManufacturedBody();
}
this.startTag(new amp.htmlparser.ParsedHtmlTag('BODY'));
default:
break;
}
}
this.handler_.pcdata(text);
Expand Down Expand Up @@ -917,17 +937,27 @@ amp.htmlparser.HtmlParser.NULL_RE_ = /\0/g;
amp.htmlparser.HtmlParser.ENTITY_RE_ = /&(#\d+|#x[0-9A-Fa-f]+|\w+);/g;

/**
* Regular expression that matches strings composed of all space characters:
* https://dev.w3.org/html5/spec-LC/common-microsyntaxes.html#space-character
* Regular expression that matches strings composed of all space characters, as
* defined in https://infra.spec.whatwg.org/#ascii-whitespace,
// and in the various HTML parsing rules at
// https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inhtml.
*
* Note: Do not USE \s to match whitespace as this includes byte order mark
* characters, which html parsing does not consider whitespace.
* @type {RegExp}
* Note: Do not USE \s to match whitespace as this includes many other
* characters that HTML parsing does not consider whitespace.
* @type {!RegExp}
* @private
*/
amp.htmlparser.HtmlParser.SPACE_RE_ =
/^[ \f\n\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000]*$/;
amp.htmlparser.HtmlParser.SPACE_RE_ = /^[ \f\n\r\t]*$/;

/**
* Regular expression that matches the characters considered whitespace by the
* C++ HTML parser.
*
* @type {!RegExp}
* @private
*/
amp.htmlparser.HtmlParser.CPP_SPACE_RE_ =
/^[ \f\n\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000]*$/;

/**
* Regular expression that matches decimal numbers.
Expand Down
2 changes: 1 addition & 1 deletion validator/engine/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -1703,6 +1703,7 @@ class TagStack {
goog.asserts.assert(query !== amp.validator.AncestorMarker.Marker.UNKNOWN);
// Skip the first element, which is "$ROOT".
for (let i = 1; i < this.stack_.length; ++i) {
if (this.stack_[i].tagSpec === null) {continue;}
const spec = this.stack_[i].tagSpec.getSpec();
if (spec.markDescendants === null) {continue;}
for (const marker of spec.markDescendants.marker) {
Expand Down Expand Up @@ -6370,7 +6371,6 @@ amp.validator.categorizeError = function(error) {
error.code ===
amp.validator.ValidationError.Code
.WARNING_EXTENSION_DEPRECATED_VERSION ||

error.code ===
amp.validator.ValidationError.Code.WARNING_TAG_REQUIRED_BY_MISSING) {
return amp.validator.ErrorCategory.Code.DEPRECATION;
Expand Down
2 changes: 1 addition & 1 deletion validator/engine/validator_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function findHtmlFilesRelativeToTestdata() {
const testFiles = [];
for (const entry of testSubdirs) {
for (const candidate of readdir(path.join(entry.root, entry.subdir))) {
if (candidate.match(/^.*.html/g)) {
if (candidate.match(/\.html$/)) {
testFiles.push(path.join(entry.subdir, candidate));
}
}
Expand Down
2 changes: 1 addition & 1 deletion validator/testdata/actions_feature_tests/amp_form.out
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,4 @@ actions_feature_tests/amp_form.html:129:2 The mandatory attribute 'action-xhr' i
| </fieldset>
| </form>
| </body>
| </html>
| </html>
2 changes: 1 addition & 1 deletion validator/testdata/actions_feature_tests/amp_list.out
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ actions_feature_tests/amp_list.html:73:2 The attribute 'cross-origin' in tag 'AM
| </template>
| </amp-list>
| </body>
| </html>
| </html>
2 changes: 1 addition & 1 deletion validator/testdata/feature_tests/manufactured_body.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Copyright 2015 The AMP HTML Authors. All Rights Reserved.
Copyright 2019 The AMP HTML Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion validator/testdata/feature_tests/manufactured_body.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FAIL
| <!--
| Copyright 2015 The AMP HTML Authors. All Rights Reserved.
| Copyright 2019 The AMP HTML Authors. All Rights Reserved.
|
| Licensed under the Apache License, Version 2.0 (the "License");
| you may not use this file except in compliance with the License.
Expand Down
34 changes: 34 additions & 0 deletions validator/testdata/feature_tests/manufactured_body_whitespace.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!--
Copyright 2019 The AMP HTML Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS-IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the license.
-->
<!--
Test Description:
This contains a U+3000 IDEOGRAPHIC SPACE in the <head> element (before the
<meta name="viewport">), which causes an implicit <body> tag to be
manufactured.
-->
<!doctype html>
<html >
<head>
<meta charset="utf-8">
<link rel="canonical" href="./regular-html-version.html">
 <meta name="viewport" content="width=device-width">
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<script async src="https://cdn.ampproject.org/v0.js"></script>
</head>
<body>
Hello, world.
</body>
</html>
37 changes: 37 additions & 0 deletions validator/testdata/feature_tests/manufactured_body_whitespace.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FAIL
| <!--
| Copyright 2019 The AMP HTML Authors. All Rights Reserved.
|
| Licensed under the Apache License, Version 2.0 (the "License");
| you may not use this file except in compliance with the License.
| You may obtain a copy of the License at
|
| http://www.apache.org/licenses/LICENSE-2.0
|
| Unless required by applicable law or agreed to in writing, software
| distributed under the License is distributed on an "AS-IS" BASIS,
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
| See the License for the specific language governing permissions and
| limitations under the license.
| -->
| <!--
| Test Description:
| This contains a U+3000 IDEOGRAPHIC SPACE in the <head> element (before the
| <meta name="viewport">), which causes an implicit <body> tag to be
| manufactured.
| -->
| <!doctype html>
| <html ⚡>
| <head>
| <meta charset="utf-8">
| <link rel="canonical" href="./regular-html-version.html">
>> ^~~~~~~~~
feature_tests/manufactured_body_whitespace.html:26:59 Tag or text which is only allowed inside the body section found outside of the body section. [DISALLOWED_HTML]
|  <meta name="viewport" content="width=device-width">
| <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
| <script async src="https://cdn.ampproject.org/v0.js"></script>
| </head>
| <body>
| Hello, world.
| </body>
| </html>
28 changes: 28 additions & 0 deletions validator/testdata/feature_tests/not_amp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!--
Copyright 2019 The AMP HTML Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS-IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the license.
-->
<!--
Test Description:
This is a basic non-amp document.
-->
<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
Hello, world.
</body>
</html>
43 changes: 43 additions & 0 deletions validator/testdata/feature_tests/not_amp.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
FAIL
| <!--
| Copyright 2019 The AMP HTML Authors. All Rights Reserved.
|
| Licensed under the Apache License, Version 2.0 (the "License");
| you may not use this file except in compliance with the License.
| You may obtain a copy of the License at
|
| http://www.apache.org/licenses/LICENSE-2.0
|
| Unless required by applicable law or agreed to in writing, software
| distributed under the License is distributed on an "AS-IS" BASIS,
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
| See the License for the specific language governing permissions and
| limitations under the license.
| -->
| <!--
| Test Description:
| This is a basic non-amp document.
| -->
| <!doctype html>
| <html>
>> ^~~~~~~~~
feature_tests/not_amp.html:21:0 The mandatory attribute '⚡' is missing in tag 'html'. (see https://www.ampproject.org/docs/reference/spec#required-markup) [MANDATORY_AMP_TAG_MISSING_OR_INCORRECT]
| <head>
| <meta charset="utf-8">
| </head>
| <body>
| Hello, world.
| </body>
| </html>
>> ^~~~~~~~~
feature_tests/not_amp.html:28:6 The mandatory tag 'link rel=canonical' is missing or incorrect. (see https://www.ampproject.org/docs/reference/spec#required-markup) [MANDATORY_AMP_TAG_MISSING_OR_INCORRECT]
>> ^~~~~~~~~
feature_tests/not_amp.html:28:6 The mandatory tag 'meta name=viewport' is missing or incorrect. (see https://www.ampproject.org/docs/reference/spec#required-markup) [MANDATORY_AMP_TAG_MISSING_OR_INCORRECT]
>> ^~~~~~~~~
feature_tests/not_amp.html:28:6 The mandatory tag 'head > style[amp-boilerplate]' is missing or incorrect. (see https://github.com/ampproject/amphtml/blob/master/spec/amp-boilerplate.md) [MANDATORY_AMP_TAG_MISSING_OR_INCORRECT]
>> ^~~~~~~~~
feature_tests/not_amp.html:28:6 The mandatory tag 'noscript > style[amp-boilerplate]' is missing or incorrect. (see https://github.com/ampproject/amphtml/blob/master/spec/amp-boilerplate.md) [MANDATORY_AMP_TAG_MISSING_OR_INCORRECT]
>> ^~~~~~~~~
feature_tests/not_amp.html:28:6 The mandatory tag 'amphtml engine v0.js script' is missing or incorrect. (see https://www.ampproject.org/docs/reference/spec#required-markup) [MANDATORY_AMP_TAG_MISSING_OR_INCORRECT]
>> ^~~~~~~~~
feature_tests/not_amp.html:28:6 The mandatory tag 'noscript enclosure for boilerplate' is missing or incorrect. (see https://github.com/ampproject/amphtml/blob/master/spec/amp-boilerplate.md) [MANDATORY_AMP_TAG_MISSING_OR_INCORRECT]
2 changes: 1 addition & 1 deletion validator/validator-main.protoascii
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ min_validator_revision_required: 375
# newer versions of the spec file. This is currently a Google internal
# mechanism, validator.js does not use this facility. However, any
# change to this file (validator-main.js) requires updating this revision id.
spec_file_revision: 846
spec_file_revision: 851

styles_spec_url: "https://www.ampproject.org/docs/guides/author-develop/responsive/style_pages"
script_spec_url: "https://www.ampproject.org/docs/reference/spec#html-tags"
Expand Down

0 comments on commit a5f911e

Please sign in to comment.