mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
fix(lint): match a timed wrapper's close tag literally (#8028)
* fix(lint): match a timed wrapper's close tag literally The parser keeps any tag name up to whitespace, / or >, so a wrapper's name can hold regex syntax. closeTag built its pattern from the raw name: an unbalanced name threw a SyntaxError that rejected the whole lint, and a nested-quantifier name backtracked exponentially over the text before a nested video. Escape the name with the file's own escapeRegExp. * refactor(lint): name the escaped close-tag pattern instead of commenting it The comment ratchet keeps a file's comment share from rising.
This commit is contained in:
@@ -419,6 +419,35 @@ describe("media rules", () => {
|
||||
expect(audio).toContain('data-start="0"');
|
||||
});
|
||||
|
||||
// The parser keeps any tag name up to whitespace, `/` or `>`, so a wrapper's name can hold
|
||||
// regex syntax. Its close tag must be matched literally: unescaped, `x(` throws and a
|
||||
// nested-quantifier name backtracks exponentially over the text before the video.
|
||||
it("matches a timed wrapper's close tag literally whatever its name holds", async () => {
|
||||
const nestedCodes = async (body: string) =>
|
||||
(
|
||||
await lintHyperframeHtml(`
|
||||
<html><body>
|
||||
<div id="root" data-composition-id="c1" data-width="1920" data-height="1080">${body}</div>
|
||||
<script>window.__timelines = window.__timelines || {}; window.__timelines["c1"] = gsap.timeline({ paused: true });</script>
|
||||
</body></html>`)
|
||||
).findings.map((f) => f.code);
|
||||
const video = `<video id="v" src="a.mp4" data-start="0" data-duration="5" muted></video>`;
|
||||
|
||||
expect(await nestedCodes(`<x( data-start="0" data-duration="5">${video}</x(>`)).toContain(
|
||||
"video_nested_in_timed_element",
|
||||
);
|
||||
expect(await nestedCodes(`<x( data-start="0" data-duration="3"></x(>${video}`)).not.toContain(
|
||||
"video_nested_in_timed_element",
|
||||
);
|
||||
|
||||
const started = performance.now();
|
||||
const backtracking = await nestedCodes(
|
||||
`<a(b+)+c data-start="0" data-duration="5"><span title="</a${"b".repeat(29)}!"></span>${video}</a(b+)+c>`,
|
||||
);
|
||||
expect(performance.now() - started).toBeLessThan(2000);
|
||||
expect(backtracking).toContain("video_nested_in_timed_element");
|
||||
});
|
||||
|
||||
it("allows audible video clips to omit muted when data-has-audio is true", async () => {
|
||||
const html = `
|
||||
<html><body>
|
||||
|
||||
@@ -445,7 +445,7 @@ const VOID_ELEMENTS = new Set([
|
||||
"wbr",
|
||||
]);
|
||||
|
||||
const closeTag = (name: string) => new RegExp(`</${name}>`, "gi");
|
||||
const literalCloseTag = (name: string) => new RegExp(`</${escapeRegExp(name)}>`, "gi");
|
||||
|
||||
function innermostTimedWrapper(
|
||||
source: string,
|
||||
@@ -465,9 +465,9 @@ function innermostTimedWrapper(
|
||||
...tags
|
||||
.filter((t) => t.name === parent.name && t.index > parent.index && t.index < media.index)
|
||||
.map((t): [number, 1] => [t.index, 1]),
|
||||
...[...source.substring(parent.index, media.index).matchAll(closeTag(parent.name))].map(
|
||||
(m): [number, -1] => [parent.index + m.index, -1],
|
||||
),
|
||||
...[
|
||||
...source.substring(parent.index, media.index).matchAll(literalCloseTag(parent.name)),
|
||||
].map((m): [number, -1] => [parent.index + m.index, -1]),
|
||||
];
|
||||
let depth = 1;
|
||||
for (const [, delta] of events.sort((x, y) => x[0] - y[0])) {
|
||||
|
||||
Reference in New Issue
Block a user