Skip to content

Commit

Permalink
cl/352843044 Allow @-moz-document (#32133)
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Grothaus committed Jan 22, 2021
1 parent cd01a15 commit e5a682e
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 4 deletions.
12 changes: 9 additions & 3 deletions validator/js/engine/validator.js
Expand Up @@ -1993,7 +1993,13 @@ class TagStack {
*/
function isAtRuleValid(cssSpec, atRuleName) {
for (const atRuleSpec of cssSpec.atRuleSpec) {
if (atRuleSpec.name === parse_css.stripVendorPrefix(atRuleName)) {
// "-moz-document" is specified in the list of allowed rules with an
// explicit vendor prefix. The idea here is that only this specific vendor
// prefix is allowed, not "-ms-document" or even "document". We first search
// the allowed list for the seen `at_rule_name` with stripped vendor prefix,
// then if not found, we search again without sripping the vendor prefix.
if (atRuleSpec.name === parse_css.stripVendorPrefix(atRuleName) ||
atRuleSpec.name === atRuleName) {
return true;
}
}
Expand Down Expand Up @@ -2165,6 +2171,7 @@ function GenCssParsingConfig() {
ampAtRuleParsingSpec['media'] = parse_css.BlockType.PARSE_AS_RULES;
ampAtRuleParsingSpec['page'] = parse_css.BlockType.PARSE_AS_DECLARATIONS;
ampAtRuleParsingSpec['supports'] = parse_css.BlockType.PARSE_AS_RULES;
ampAtRuleParsingSpec['-moz-document'] = parse_css.BlockType.PARSE_AS_RULES;
const config = {
atRuleSpec: ampAtRuleParsingSpec,
defaultSpec: parse_css.BlockType.PARSE_AS_IGNORE,
Expand Down Expand Up @@ -5917,8 +5924,7 @@ class ParsedValidatorRules {
let tagSpec = this.rules_.tags[tagSpecId];
if (tagSpec.extensionSpec == null) continue;
if (tagSpec.specName === null)
tagSpec.specName =
tagSpec.extensionSpec.name + ' extension script';
tagSpec.specName = tagSpec.extensionSpec.name + ' extension script';
if (tagSpec.descriptiveName === null)
tagSpec.descriptiveName = tagSpec.specName;
tagSpec.mandatoryParent = 'HEAD';
Expand Down
40 changes: 40 additions & 0 deletions validator/testdata/feature_tests/css-moz-document.html
@@ -0,0 +1,40 @@
<!--
Copyright 2021 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:
Tests usage of `@-moz-document` in the style tag CSS. See
https://github.com/ampproject/amphtml/issues/26406 for the original context.
-->
<!doctype html>
<html >
<head>
<meta charset="utf-8">
<link rel="canonical" href="./regular-html-version.html">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,minimal-ui">
<style amp-custom>
/* Valid: */
@-moz-document url-prefix() {}
@-moz-document url-prefix(https://site.example) {}
/* Invalid: Only -moz- prefix supported */
@-ms-document url-prefix() {}
@document url-prefix() {}
</style>
<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 src="https://cdn.ampproject.org/v0.js" async></script>
</head>
<body>
</body>
</html>
45 changes: 45 additions & 0 deletions validator/testdata/feature_tests/css-moz-document.out
@@ -0,0 +1,45 @@
FAIL
| <!--
| Copyright 2021 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:
| Tests usage of `@-moz-document` in the style tag CSS. See
| https://github.com/ampproject/amphtml/issues/26406 for the original context.
| -->
| <!doctype html>
| <html ⚡>
| <head>
| <meta charset="utf-8">
| <link rel="canonical" href="./regular-html-version.html">
| <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,minimal-ui">
| <style amp-custom>
| /* Valid: */
| @-moz-document url-prefix() {}
| @-moz-document url-prefix(https://site.example) {}
| /* Invalid: Only -moz- prefix supported */
| @-ms-document url-prefix() {}
>> ^~~~~~~~~
feature_tests/css-moz-document.html:32:4 CSS syntax error in tag 'style amp-custom' - saw invalid at rule '@-ms-document'.
| @document url-prefix() {}
>> ^~~~~~~~~
feature_tests/css-moz-document.html:33:4 CSS syntax error in tag 'style amp-custom' - saw invalid at rule '@document'.
| </style>
| <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 src="https://cdn.ampproject.org/v0.js" async></script>
| </head>
| <body>
| </body>
| </html>
2 changes: 2 additions & 0 deletions validator/validator-css.protoascii
Expand Up @@ -785,6 +785,8 @@ tags: { # <style amp-custom>, [AMP]
at_rule_spec: { name: 'media' }
at_rule_spec: { name: 'page' }
at_rule_spec: { name: 'supports' }
# https://github.com/ampproject/amphtml/issues/26406
at_rule_spec: { name: '-moz-document' }
}
disallowed_cdata_regex: {
regex: "<!--"
Expand Down
2 changes: 1 addition & 1 deletion validator/validator-main.protoascii
Expand Up @@ -26,7 +26,7 @@ min_validator_revision_required: 475
# 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: 1137
spec_file_revision: 1138

styles_spec_url: "https://amp.dev/documentation/guides-and-tutorials/develop/style_and_layout/style_pages/"
script_spec_url: "https://amp.dev/documentation/guides-and-tutorials/learn/validation-workflow/validation_errors/#custom-javascript-is-not-allowed"
Expand Down

0 comments on commit e5a682e

Please sign in to comment.