Skip to content

Commit 41237c9

Browse files
committed
fix(studio): scope the data-hf-id strip to tag brackets, not text content
A clip's visible text can contain the literal string data-hf-id="..."; the previous whole-string regex stripped it as if it were the attribute, corrupting the copied text. Reproduced and confirmed the fix with a test.
1 parent ca084da commit 41237c9

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎packages/studio/src/hooks/useClipboard.test.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,33 @@ describe("pasteTimelineClips", () => {
8686
expect(content).not.toContain("data-hf-id");
8787
});
8888

89-
it("only strips the root's own data-hf-id, not one on a nested descendant", () => {
89+
it("strips a nested descendant's data-hf-id too, not just the root's", () => {
90+
// A composition-instance clip's descendants carry their own hf-ids; a
91+
// clone must remint all of them, not just the root, or the descendants
92+
// collide with their originals the same way the root would.
9093
const nested: TimelineClipboardClip = {
9194
html: '<div data-hf-id="hf-root" id="comp-1" data-start="7.8" data-duration="0.57" data-track-index="109"><span data-hf-id="hf-child"></span></div>',
9295
start: 7.8,
9396
duration: 0.57,
9497
track: 109,
9598
};
9699
const { content } = pasteTimelineClips(ROOT, [nested], 40, []);
100+
expect(content).not.toContain("hf-root");
101+
expect(content).not.toContain("hf-child");
97102
expect(content).not.toContain("data-hf-id");
98103
});
99104

105+
it("does not strip text content that happens to contain the data-hf-id string", () => {
106+
const withText: TimelineClipboardClip = {
107+
html: '<div id="cap-1" data-start="7.8" data-duration="0.57" data-track-index="109"><span>talking about data-hf-id="hf-xyz" in my video</span></div>',
108+
start: 7.8,
109+
duration: 0.57,
110+
track: 109,
111+
};
112+
const { content } = pasteTimelineClips(ROOT, [withText], 40, []);
113+
expect(content).toContain('talking about data-hf-id="hf-xyz" in my video');
114+
});
115+
100116
it("bumps the second clip in a batch off the first clip's own new track when their offsets collide", () => {
101117
// Both clips start life a track apart but paste to overlapping times on
102118
// the SAME track, so the second must dodge the first's placement, not

‎packages/studio/src/hooks/useClipboard.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,11 @@ export function pasteTimelineClips(
115115
for (const clip of clips) {
116116
// data-hf-id is pinned once minted (hfIdAssignment.ts never repairs an
117117
// existing one), so a raw clone would keep the source's id forever.
118-
const stripped = clip.html.replace(/\sdata-hf-id="[^"]*"/g, "");
118+
// Scoped to tag brackets so a clip's visible text content can't be
119+
// mistaken for the attribute if it happens to contain the same string.
120+
const stripped = clip.html.replace(/<[^>]+>/g, (tag) =>
121+
tag.replace(/\sdata-hf-id="[^"]*"/g, ""),
122+
);
119123
const deduped = deduplicateIds(stripped, existingIds);
120124
existingIds = existingIds.concat(collectHtmlIds(deduped));
121125
const newStart = anchorTime + (clip.start - groupMinStart);

0 commit comments

Comments
 (0)