-
Notifications
You must be signed in to change notification settings - Fork 0
fix: rewrite data-src/data-srcset for lazy-loaded images #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -107,4 +107,14 @@ describe("HTMLRewriter integration", () => { | |||||||||||||
| expect(resp.headers.get("content-security-policy")).toBeNull(); | ||||||||||||||
| expect(resp.headers.get("access-control-allow-origin")).toBe("*"); | ||||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
| it("rewrites data-src attributes for lazy-loaded images", async () => { | ||||||||||||||
| const resp = await worker.fetch("/browse/https://www.wired.com"); | ||||||||||||||
| if (resp.status !== 200) return; | ||||||||||||||
| const html = await resp.text(); | ||||||||||||||
| const dataSrcMatches = html.match(/data-src="([^"]*)"/g) || []; | ||||||||||||||
| if (dataSrcMatches.length === 0) return; // skip if wired changed their pattern | ||||||||||||||
| const allProxied = dataSrcMatches.every((m) => m.includes("/browse/")); | ||||||||||||||
|
Comment on lines
+115
to
+117
|
||||||||||||||
| const dataSrcMatches = html.match(/data-src="([^"]*)"/g) || []; | |
| if (dataSrcMatches.length === 0) return; // skip if wired changed their pattern | |
| const allProxied = dataSrcMatches.every((m) => m.includes("/browse/")); | |
| const dataSrcMatches = [...html.matchAll(/data-src="([^"]*)"/g)]; | |
| if (dataSrcMatches.length === 0) return; // skip if wired changed their pattern | |
| const allProxied = dataSrcMatches.every((m) => m[1].startsWith("/browse/")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test can pass without asserting the new behavior: it returns early when Wired is down/non-200, and also returns early when no
data-srcattributes are present. That makes CI green even if the rewrite regresses or Wired changes/blocks requests. Consider using Vitest's skip mechanism (so it shows as skipped) and/or make the test deterministic by transforming a small HTML fixture throughbuildRewriter()and asserting the rewrittendata-srcvalue(s).