diff --git a/packages/core/src/lint/utils.ts b/packages/core/src/lint/utils.ts index 7ff05ec5f1..cf8a7b121b 100644 --- a/packages/core/src/lint/utils.ts +++ b/packages/core/src/lint/utils.ts @@ -59,12 +59,18 @@ export function extractBlocks(source: string, pattern: RegExp): ExtractedBlock[] } export function findRootTag(source: string): OpenTag | null { - const bodyMatch = source.match(/
]*>([\s\S]*?)<\/body>/i); - const bodyContent = bodyMatch ? (bodyMatch[1] ?? source) : source; + const bodyOpenMatch = /]*>/i.exec(source); + const bodyCloseMatch = /<\/body>/i.exec(source); + const bodyStart = bodyOpenMatch ? bodyOpenMatch.index + bodyOpenMatch[0].length : 0; + const bodyEnd = + bodyOpenMatch && bodyCloseMatch && bodyCloseMatch.index > bodyStart + ? bodyCloseMatch.index + : source.length; + const bodyContent = bodyOpenMatch ? source.slice(bodyStart, bodyEnd) : source; const bodyTags = extractOpenTags(bodyContent); for (const tag of bodyTags) { if (["script", "style", "meta", "link", "title"].includes(tag.name)) continue; - return tag; + return { ...tag, index: tag.index + bodyStart }; } return null; } diff --git a/packages/studio/src/player/hooks/useTimelinePlayer.test.ts b/packages/studio/src/player/hooks/useTimelinePlayer.test.ts index d5366af0d4..2c89583f23 100644 --- a/packages/studio/src/player/hooks/useTimelinePlayer.test.ts +++ b/packages/studio/src/player/hooks/useTimelinePlayer.test.ts @@ -195,6 +195,35 @@ describe("anonymous timeline identity", () => { expect(new Set(elements.map((element) => element.key)).size).toBe(2); expect(elements.map((element) => element.selectorIndex)).toEqual([0, 1]); }); + + it("reads media metadata from owner-window media elements", () => { + const doc = createDocument(` +