Skip to content

Commit 4995be1

Browse files
committed
fix(studio): apply quote boundaries to active source writers
1 parent 456e527 commit 4995be1

4 files changed

Lines changed: 40 additions & 4 deletions

File tree

‎packages/studio/src/components/editor/colorGradingScopePatch.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@ import { describe, expect, it } from "vitest";
22
import { patchMediaColorGradingInHtml } from "./colorGradingScopePatch";
33

44
describe("patchMediaColorGradingInHtml", () => {
5+
it.each(['"', "'"])("replaces and removes long grading values quoted with %s", (quote) => {
6+
const otherQuote = quote === '"' ? "'" : '"';
7+
for (const value of [
8+
"",
9+
"line1\nline2",
10+
"a".repeat(100_000),
11+
`data-color-grading=${otherQuote}a`.repeat(10_000),
12+
]) {
13+
const html = `<img alt="kept"\tDATA-COLOR-GRADING=${quote}${value}${quote} />`;
14+
expect(patchMediaColorGradingInHtml(html, "new")).toEqual({
15+
html: '<img alt="kept" data-color-grading="new" />',
16+
count: 1,
17+
});
18+
expect(patchMediaColorGradingInHtml(html, null)).toEqual({
19+
html: '<img alt="kept" />',
20+
count: 1,
21+
});
22+
}
23+
});
24+
525
it("adds color grading to video and image tags only", () => {
626
const { html, count } = patchMediaColorGradingInHtml(
727
`<div><video id="v"></video><img id="i" /><audio id="a"></audio></div>`,

‎packages/studio/src/components/editor/colorGradingScopePatch.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const MEDIA_TAG_RE = /<\s*(video|img)\b(?:[^>"']|"[^"]*"|'[^']*')*>/gi;
2-
const COLOR_GRADING_ATTR_RE = /\sdata-color-grading=(["'])([\s\S]*?)\1/i;
2+
const COLOR_GRADING_ATTR_RE = /\sdata-color-grading=(?:"[^"]*"|'[^']*')/i;
33
const IGNORED_HTML_RANGE_RE = /<!--[\s\S]*?-->|<(script|style)\b[\s\S]*?<\/\1\s*>/gi;
44

55
interface TextRange {

‎packages/studio/src/utils/sourcePatcher.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ import {
88
} from "./sourcePatcher";
99

1010
describe("applyPatchByTarget", () => {
11+
it.each(['"', "'"])("patches long and multiline styles quoted with %s", (quote) => {
12+
const otherQuote = quote === '"' ? "'" : '"';
13+
const op: PatchOperation = { type: "inline-style", property: "opacity", value: "0.5" };
14+
for (const value of [
15+
"",
16+
"line1\nline2",
17+
"a".repeat(100_000),
18+
`style=${otherQuote}a`.repeat(10_000),
19+
]) {
20+
const html = `<img id="hero" class="hero" style=${quote}--label:${value}${quote} />`;
21+
const expected = `<img id="hero" class="hero" style=${quote}--label: ${value}; opacity: 0.5${quote} />`;
22+
expect(applyPatch(html, "hero", op)).toBe(expected);
23+
expect(applyPatchByTarget(html, { selector: ".hero" }, op)).toBe(expected);
24+
}
25+
});
26+
1127
it("updates a composition host by data-composition-id selector", () => {
1228
const html = `<div data-composition-id="intro" data-start="0" data-track-index="1"></div>`;
1329
const op: PatchOperation = { type: "attribute", property: "start", value: "2.5" };

‎packages/studio/src/utils/sourcePatcher.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ function patchInlineStyleInTag(
184184
if (!tag) return html;
185185

186186
// Check if there's an existing style attribute
187-
const styleMatch = /\bstyle=(["'])([\s\S]*?)\1/.exec(tag);
187+
const styleMatch = /\bstyle=(")([^"]*)"|\bstyle=(')([^']*)'/.exec(tag);
188188
if (styleMatch) {
189-
const existingStyle = styleMatch[2];
190-
const quote = styleMatch[1];
189+
const existingStyle = styleMatch[2] ?? styleMatch[4];
190+
const quote = styleMatch[1] ?? styleMatch[3];
191191
// Parse existing properties
192192
const props = new Map<string, string>();
193193
for (const part of splitInlineStyleDeclarations(existingStyle)) {

0 commit comments

Comments
 (0)