mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-11 23:00:03 +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:
@@ -77,6 +77,46 @@ ${headContent}
|
||||
}
|
||||
|
||||
describe("core rules", () => {
|
||||
it("does not lint scripts embedded inside an iframe srcdoc attribute", async () => {
|
||||
const html = `
|
||||
<html><body>
|
||||
<div data-composition-id="root" data-width="1280" data-height="720"></div>
|
||||
<iframe srcdoc="<script>const child = gsap.timeline({ paused: true }); child.to("#x", { opacity: 1 });</script>"></iframe>
|
||||
<script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
|
||||
<script>
|
||||
window.__timelines = window.__timelines || {};
|
||||
const rootTl = gsap.timeline({ paused: true });
|
||||
window.__timelines["root"] = rootTl;
|
||||
</script>
|
||||
</body></html>`;
|
||||
|
||||
const result = await lintHyperframeHtml(html);
|
||||
|
||||
expect(
|
||||
result.findings.find((finding) => finding.code === "invalid_inline_script_syntax"),
|
||||
).toBeUndefined();
|
||||
expect(
|
||||
result.findings.find((finding) => finding.code === "gsap_timeline_not_registered"),
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not lint elements embedded inside an iframe srcdoc attribute", async () => {
|
||||
const html = `
|
||||
<html><body>
|
||||
<div data-composition-id="root" data-width="1280" data-height="720"></div>
|
||||
<iframe srcdoc='<video src="child.mp4" data-start="0"></video>'></iframe>
|
||||
<script>window.__timelines = {};</script>
|
||||
</body></html>`;
|
||||
|
||||
const result = await lintHyperframeHtml(html);
|
||||
|
||||
expect(
|
||||
result.findings.find(
|
||||
(finding) => finding.elementId === undefined && finding.message.includes("<video"),
|
||||
),
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("warns when an id starts with a digit and is unsafe in a hash selector", async () => {
|
||||
const html = `
|
||||
<html><body>
|
||||
|
||||
Reference in New Issue
Block a user