@@ -311,62 +311,42 @@ ScriptTag ParseScriptTag(htmlparser::Node* node) {
311
311
}
312
312
}
313
313
314
- if (src.empty ()) {
315
- return script_tag;
316
- }
317
-
318
- std::string src_str{src};
319
314
// Determine if this has a valid AMP domain and separate the path from the
320
315
// attribute 'src'. Consumes the domain making src just the path.
321
316
if (absl::ConsumePrefix (&src, kAmpProjectDomain )) {
322
317
script_tag.is_amp_domain = true ;
323
- script_tag.path = src_str;
324
- } else {
325
- script_tag.is_amp_domain = false ;
326
- htmlparser::URL url (src_str);
327
- // Error cases, early exit:
328
- if (!url.is_valid ()) return script_tag;
329
- if (!url.has_protocol ()) return script_tag;
330
- if (url.protocol () != " https" && url.protocol () != " http" )
331
- return script_tag;
332
- if (url.hostname ().empty ()) return script_tag;
333
-
334
- src = url.path_params_fragment ().data ();
335
- // Trim the "/" prefix as this is what kExtensionPathRe expects.
336
- if (!src.empty () && src[0 ] == ' /' ) src = src.substr (1 );
337
- std::string src_str{src};
338
- script_tag.path = src_str;
339
- }
340
-
341
- // Only look at script tags that have attribute 'async'.
342
- if (has_async_attr) {
343
- // Determine if this is the AMP Runtime.
344
- if (!script_tag.is_extension &&
345
- RE2::FullMatch (src, *kRuntimeScriptPathRe )) {
346
- script_tag.is_runtime = true ;
347
- script_tag.has_valid_path = true ;
348
- }
349
-
350
- // For AMP Extensions, validate path and extract name and version.
351
- if (script_tag.is_extension &&
352
- RE2::FullMatch (src, *kExtensionPathRe , &script_tag.extension_name ,
353
- &script_tag.extension_version )) {
354
- script_tag.has_valid_path = true ;
355
- }
356
-
357
- // Determine the release version (LTS, module, standard, etc).
358
- if ((has_module_attr && RE2::FullMatch (src, *kModuleLtsScriptPathRe )) ||
359
- (has_nomodule_attr && RE2::FullMatch (src, *kLtsScriptPathRe ))) {
360
- script_tag.release_version = ScriptReleaseVersion::MODULE_NOMODULE_LTS;
361
- } else if ((has_module_attr &&
362
- RE2::FullMatch (src, *kModuleScriptPathRe )) ||
363
- (has_nomodule_attr &&
364
- RE2::FullMatch (src, *kStandardScriptPathRe ))) {
365
- script_tag.release_version = ScriptReleaseVersion::MODULE_NOMODULE;
366
- } else if (RE2::FullMatch (src, *kLtsScriptPathRe )) {
367
- script_tag.release_version = ScriptReleaseVersion::LTS;
368
- } else if (RE2::FullMatch (src, *kStandardScriptPathRe )) {
369
- script_tag.release_version = ScriptReleaseVersion::STANDARD;
318
+ script_tag.path = std::string (src);
319
+
320
+ // Only look at script tags that have attribute 'async'.
321
+ if (has_async_attr) {
322
+ // Determine if this is the AMP Runtime.
323
+ if (!script_tag.is_extension &&
324
+ RE2::FullMatch (src, *kRuntimeScriptPathRe )) {
325
+ script_tag.is_runtime = true ;
326
+ script_tag.has_valid_path = true ;
327
+ }
328
+
329
+ // For AMP Extensions, validate path and extract name and version.
330
+ if (script_tag.is_extension &&
331
+ RE2::FullMatch (src, *kExtensionPathRe , &script_tag.extension_name ,
332
+ &script_tag.extension_version )) {
333
+ script_tag.has_valid_path = true ;
334
+ }
335
+
336
+ // Determine the release version (LTS, module, standard, etc).
337
+ if ((has_module_attr && RE2::FullMatch (src, *kModuleLtsScriptPathRe )) ||
338
+ (has_nomodule_attr && RE2::FullMatch (src, *kLtsScriptPathRe ))) {
339
+ script_tag.release_version = ScriptReleaseVersion::MODULE_NOMODULE_LTS;
340
+ } else if ((has_module_attr &&
341
+ RE2::FullMatch (src, *kModuleScriptPathRe )) ||
342
+ (has_nomodule_attr &&
343
+ RE2::FullMatch (src, *kStandardScriptPathRe ))) {
344
+ script_tag.release_version = ScriptReleaseVersion::MODULE_NOMODULE;
345
+ } else if (RE2::FullMatch (src, *kLtsScriptPathRe )) {
346
+ script_tag.release_version = ScriptReleaseVersion::LTS;
347
+ } else if (RE2::FullMatch (src, *kStandardScriptPathRe )) {
348
+ script_tag.release_version = ScriptReleaseVersion::STANDARD;
349
+ }
370
350
}
371
351
}
372
352
return script_tag;
@@ -1192,7 +1172,7 @@ class ParsedTagSpec {
1192
1172
1193
1173
// Whether or not the tag should be recorded via
1194
1174
// Context->RecordTagspecValidated if it was validated
1195
- // successfully . For performance, this is only done for tags that
1175
+ // successfullly . For performance, this is only done for tags that
1196
1176
// are mandatory, unique, or possibly required by some other tag.
1197
1177
RecordValidated ShouldRecordTagspecValidated () const {
1198
1178
return should_record_tagspec_validated_;
@@ -1284,7 +1264,7 @@ std::string TagSpecUrl(const TagSpec& spec) {
1284
1264
return StrCat (extension_spec_url_prefix, spec.extension_spec ().name ());
1285
1265
if (spec.requires_extension_size () > 0 )
1286
1266
// Return the first |requires_extension|, which should be the most
1287
- // representative .
1267
+ // representitive .
1288
1268
return StrCat (extension_spec_url_prefix, spec.requires_extension (0 ));
1289
1269
1290
1270
return " " ;
@@ -2834,11 +2814,11 @@ class InvalidRuleVisitor : public htmlparser::css::RuleVisitor {
2834
2814
class InvalidDeclVisitor : public htmlparser ::css::RuleVisitor {
2835
2815
public:
2836
2816
InvalidDeclVisitor (const ParsedDocCssSpec& css_spec, Context* context,
2837
- const std::string& tag_descriptive_name ,
2817
+ const std::string& tag_decriptive_name ,
2838
2818
ValidationResult* result)
2839
2819
: css_spec_(css_spec),
2840
2820
context_ (context),
2841
- tag_descriptive_name_(tag_descriptive_name ),
2821
+ tag_descriptive_name_(tag_decriptive_name ),
2842
2822
result_(result) {}
2843
2823
2844
2824
void VisitDeclaration (
@@ -3996,14 +3976,8 @@ void ValidateAmpScriptSrcAttr(const ParsedHtmlTag& tag,
3996
3976
const TagSpec& tag_spec, const Context& context,
3997
3977
ValidationResult* result) {
3998
3978
if (!tag.IsAmpDomain ()) {
3999
- bool is_amp_format =
4000
- c_find (context.type_identifiers (), TypeIdentifier::kAmp ) !=
4001
- context.type_identifiers ().end ();
4002
- if (!is_amp_format || context.is_transformed ()) {
4003
- context.AddError (ValidationError::DISALLOWED_AMP_DOMAIN,
4004
- context.line_col (),
4005
- /* params=*/ {}, /* spec_url=*/ " " , result);
4006
- }
3979
+ context.AddError (ValidationError::DISALLOWED_AMP_DOMAIN, context.line_col (),
3980
+ /* params=*/ {}, /* spec_url=*/ " " , result);
4007
3981
}
4008
3982
4009
3983
if (tag.IsExtensionScript () && tag_spec.has_extension_spec ()) {
@@ -5686,7 +5660,9 @@ class ParsedValidatorRulesProvider {
5686
5660
class Validator {
5687
5661
public:
5688
5662
Validator (const ParsedValidatorRules* rules, int max_errors = -1 )
5689
- : rules_(rules), max_errors_(max_errors), context_(rules_, max_errors_) {}
5663
+ : rules_(rules),
5664
+ max_errors_ (max_errors),
5665
+ context_(rules_, max_errors_) {}
5690
5666
5691
5667
ValidationResult Validate (const htmlparser::Document& doc) {
5692
5668
doc_metadata_ = doc.Metadata ();
0 commit comments