Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/cdn-preconnect-bare-origin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/theme-check-common': patch
---

Report `CdnPreconnect` for `href="https://cdn.shopify.com"` and `href="//cdn.shopify.com"` without a trailing path, and stop reporting hosts that only contain `cdn.shopify.com` in their path.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ describe('Module: CdnPreconnect', () => {
);
});

it('should report preconnect to cdn.shopify.com without a trailing slash', async () => {
const sourceCode = `
<link rel="preconnect" href="https://cdn.shopify.com" crossorigin>
<link rel="preconnect" href="//cdn.shopify.com">
`;

const offenses = await runLiquidCheck(CdnPreconnect, sourceCode);
expect(offenses).to.have.length(2);
});

it('should not report preconnect to other hosts', async () => {
const sourceCode = `
<link rel="preconnect" href="https://fonts.shopifycdn.com" crossorigin>
<link rel="preconnect" href="https://example.com/cdn.shopify.com.html">
`;

const offenses = await runLiquidCheck(CdnPreconnect, sourceCode);
expect(offenses).to.have.length(0);
});

it('should not report other link types', async () => {
const sourceCode = `
<link rel="preload" href="https://example.com/foo.css" as="style"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export const CdnPreconnect: LiquidCheckDefinition = {

const isShopifyCdn = node.attributes
.filter(isValuedHtmlAttribute)
.some((attr) => isAttr(attr, 'href') && valueIncludes(attr, '.+cdn.shopify.com.+'));
.some(
(attr) =>
isAttr(attr, 'href') && valueIncludes(attr, '(https?:)?//cdn\\.shopify\\.com(/\\S*)?'),
);

if (!isShopifyCdn) return;

Expand Down
Loading