mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-08 19:06:04 +00:00
fix(lint): parse HTML structure without regex (#2223)
* fix(lint): ignore scripts inside quoted attributes * Address PR review feedback (#2223) - replace repeated attribute scanner with quoted tag ranges - remove the Fallow complexity finding * refactor(lint): parse HTML structure with htmlparser2 * fix(lint): traverse template style sources * test(lint): cover nested template style sources
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { lintHyperframeHtml } from "./hyperframeLinter.js";
|
||||
import { afterEach, describe, it, expect, vi } from "vitest";
|
||||
import { lintHyperframeHtml, lintMediaUrls } from "./hyperframeLinter.js";
|
||||
|
||||
afterEach(() => vi.unstubAllGlobals());
|
||||
|
||||
describe("lintHyperframeHtml — orchestrator", () => {
|
||||
const validComposition = `
|
||||
@@ -122,3 +124,26 @@ describe("lintHyperframeHtml — orchestrator", () => {
|
||||
expect(rootFindings).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("lintMediaUrls", () => {
|
||||
it("checks top-level remote media elements", async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue({ ok: true, status: 200 });
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
|
||||
await lintMediaUrls('<img id="hero" src="https://example.com/hero.png">');
|
||||
|
||||
expect(fetchMock).toHaveBeenCalledWith(
|
||||
"https://example.com/hero.png",
|
||||
expect.objectContaining({ method: "HEAD" }),
|
||||
);
|
||||
});
|
||||
|
||||
it("ignores remote media embedded inside an iframe srcdoc attribute", async () => {
|
||||
const fetchMock = vi.fn();
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
|
||||
await lintMediaUrls(`<iframe srcdoc='<img src="https://example.com/embedded.png">'></iframe>`);
|
||||
|
||||
expect(fetchMock).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user