Remove image preload refs without href

This commit is contained in:
2026-05-16 23:03:49 -07:00
parent 0ef0360fde
commit 2b28ada9d1
2 changed files with 31 additions and 3 deletions

View File

@@ -82,6 +82,27 @@ test("external asset reporting parses srcset-like attributes without splitting U
]);
});
test("removes image preload srcsets when the link has no href", async () => {
const fetched = [];
const inliner = new AssetInliner();
inliner.fetchAsset = async (rawUrl) => {
fetched.push(rawUrl);
return {
bytes: Buffer.from("asset"),
contentType: "image/jpeg"
};
};
const output = await inliner.inlineHtml(`
<link rel="preload" as="image" imagesrcset="https://media.example/photos/id/master/w_120,c_limit/photo.jpg 120w, https://media.example/photos/id/master/w_240,c_limit/photo.jpg 240w">
`, "https://example.com/article");
assert.deepEqual(fetched, []);
assert.doesNotMatch(output, /https:\/\/media\.example/);
assert.doesNotMatch(output, /imagesrcset/);
assert.deepEqual(findExternalAssetRefs(output), []);
});
test("asset inliner skips URLs blocked by the filter hook", async () => {
const blocked = [];
const inliner = new AssetInliner({