From a52bcd66545e313f204b6a46ba025b079fd4d462 Mon Sep 17 00:00:00 2001 From: honeybadgerdontcare Date: Wed, 26 May 2021 15:20:50 +0000 Subject: [PATCH] cl/375855105 Extract AMP Cache Domain validation, part 1 --- validator/js/engine/htmlparser-interface.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/validator/js/engine/htmlparser-interface.js b/validator/js/engine/htmlparser-interface.js index 1ee0b2379551..82853f75a1ef 100644 --- a/validator/js/engine/htmlparser-interface.js +++ b/validator/js/engine/htmlparser-interface.js @@ -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} @@ -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')); }