Skip to content

Commit

Permalink
cl/375855105 Extract AMP Cache Domain validation, part 1 (ampproject#…
Browse files Browse the repository at this point in the history
…34558)

Co-authored-by: honeybadgerdontcare <sedano@google.com>
  • Loading branch information
2 people authored and rochapablo committed Aug 30, 2021
1 parent 36bd800 commit 53e6d42
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion validator/js/engine/htmlparser-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,15 @@ const ParsedHtmlTag = class {
return !!this.extensionScriptNameAttribute_();
}

/**
* Tests if this is an AMP Cache domain.
* @param {string} src
* @return {boolean}
*/
isAmpCacheDomain_(src) {
return src.startsWith('https://cdn.ampproject.org');
}

/**
* Tests if this is an async script tag.
* @return {boolean}
Expand All @@ -268,7 +277,7 @@ const ParsedHtmlTag = class {
const src = this.getAttrValueOrNull_('src');
if (src === null) return false;
return this.isAsyncScriptTag_() && !this.isExtensionScript() &&
src.startsWith('https://cdn.ampproject.org/') &&
this.isAmpCacheDomain_(src) &&
(src.endsWith('/v0.js') || src.endsWith('/v0.mjs') ||
src.endsWith('/v0.mjs?f=sxg'));
}
Expand Down

0 comments on commit 53e6d42

Please sign in to comment.