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

Sync for validator cpp engine and cpp htmlparser #37497

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions validator/cpp/engine/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ cc_library(
copts = ["-std=c++17"],
deps = [
":validator-internal",
"//cpp/htmlparser/css:parse-css",
"//:validator_cc_proto",
],
alwayslink = 1,
Expand Down Expand Up @@ -329,6 +330,7 @@ cc_test(
":testing-utils",
":validator",
":validator_pb",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest_main",
"//cpp/htmlparser/css:parse_css_cc_proto",
Expand Down
32 changes: 16 additions & 16 deletions validator/cpp/engine/validator-internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ static const LazyRE2 kRuntimeScriptPathRe = {
static const LazyRE2 kExtensionPathRe = {
R"re((?:lts/)?v0/(amp-[a-z0-9-]*)-([a-z0-9.]*)\.(?:m)?js(?:\?f=sxg)?)re"};

// Generates a htmlparser::css::CssParsingConfig.
CssParsingConfig GenCssParsingConfig() {
CssParsingConfig config;
// If other @ rule types are added to the rules, their block parsing types
// will need to be added here as well.
config.at_rule_spec["font-face"] = BlockType::PARSE_AS_DECLARATIONS;
config.at_rule_spec["keyframes"] = BlockType::PARSE_AS_RULES;
config.at_rule_spec["media"] = BlockType::PARSE_AS_RULES;
config.at_rule_spec["page"] = BlockType::PARSE_AS_DECLARATIONS;
config.at_rule_spec["supports"] = BlockType::PARSE_AS_RULES;
config.at_rule_spec["-moz-document"] = BlockType::PARSE_AS_RULES;
// Note that ignoring still generates an error.
config.default_spec = BlockType::PARSE_AS_IGNORE;
return config;
}

namespace {

#define CHECK_NOTNULL(x) (x)
Expand Down Expand Up @@ -845,22 +861,6 @@ class ParsedAttrSpecs {
unordered_map<std::string, vector<const ParsedAttrSpec*>> attr_lists_by_name_;
};

// Generates a htmlparser::css::CssParsingConfig.
CssParsingConfig GenCssParsingConfig() {
CssParsingConfig config;
// If other @ rule types are added to the rules, their block parsing types
// will need to be added here as well.
config.at_rule_spec["font-face"] = BlockType::PARSE_AS_DECLARATIONS;
config.at_rule_spec["keyframes"] = BlockType::PARSE_AS_RULES;
config.at_rule_spec["media"] = BlockType::PARSE_AS_RULES;
config.at_rule_spec["page"] = BlockType::PARSE_AS_DECLARATIONS;
config.at_rule_spec["supports"] = BlockType::PARSE_AS_RULES;
config.at_rule_spec["-moz-document"] = BlockType::PARSE_AS_RULES;
// Note that ignoring still generates an error.
config.default_spec = BlockType::PARSE_AS_IGNORE;
return config;
}

// Instances of this class precompute the regular expressions for a particular
// Cdata specification.
class ParsedCdataSpec {
Expand Down
2 changes: 2 additions & 0 deletions validator/cpp/engine/validator.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#ifndef CPP_ENGINE_VALIDATOR_H_
#define CPP_ENGINE_VALIDATOR_H_

#include "cpp/htmlparser/css/parse-css.h"
#include "cpp/htmlparser/document.h"
#include "validator.pb.h"

Expand All @@ -38,6 +39,7 @@ ValidationResult Validate(std::string_view html,

int RulesSpecVersion();
int ValidatorVersion();
htmlparser::css::CssParsingConfig GenCssParsingConfig();

} // namespace amp::validator

Expand Down
Loading