The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.
Studio: a url() with an open quote fails at once (#68)
riverisbuildingc164fee480a3
diff --git a/.changeset/css-url-quick-fail.md b/.changeset/css-url-quick-fail.mdnew file mode 100644index 0000000..7c7b94d--- /dev/null+++ b/.changeset/css-url-quick-fail.md@@ -0,0 +1,5 @@+---+'openfilm': patch+---++Studio: a picture's `url()` left with an open quote in a page's changes no longer stalls the editor.diff --git a/packages/openfilm/studio/ui/src/lib/template-controls.test.ts b/packages/openfilm/studio/ui/src/lib/template-controls.test.tsindex 745c5ce..e783913 100644--- a/packages/openfilm/studio/ui/src/lib/template-controls.test.ts+++ b/packages/openfilm/studio/ui/src/lib/template-controls.test.ts@@ -69,6 +69,11 @@ it('a picture put in a page is named from the page\'s folder, as CSS writes a urassert.equal(urlOf("url('x.png')"), 'x.png');assert.equal(urlOf('url(x.png)'), 'x.png');assert.equal(urlOf('none'), null);+ assert.equal(urlOf('url("a\\"b.png")'), 'a"b.png');+ const open = Date.now();+ assert.equal(urlOf(`url("${'\\!'.repeat(40)}`), null);+ assert.equal(urlOf(`url('${'\\&'.repeat(40)}`), null);+ assert.ok(Date.now() - open < 100, 'a quote left open fails at once');});it('a picture is replaced with the CSS that draws another file in its place: content for an <img>, a background for a box', () => {diff --git a/packages/openfilm/studio/ui/src/lib/template-controls.ts b/packages/openfilm/studio/ui/src/lib/template-controls.tsindex 3db606b..3f57a4b 100644--- a/packages/openfilm/studio/ui/src/lib/template-controls.ts+++ b/packages/openfilm/studio/ui/src/lib/template-controls.ts@@ -108,9 +108,9 @@ export function relativeTo(page: string, path: string): string {/** A file's place as CSS writes it. */export const cssUrl = (path: string) => `url("${path.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}")`;-/** The place a CSS `url()` names, or null. */+/** The place a CSS `url()` names, or null. A backslash only starts an escape, so a quote left open fails at once. */export function urlOf(css: string | null | undefined): string | null {- const m = /^\s*url\(\s*(?:"((?:\\.|[^"])*)"|'((?:\\.|[^'])*)'|([^)\s]*))\s*\)\s*$/.exec(css ?? '');+ const m = /^\s*url\(\s*(?:"((?:\\.|[^"\\])*)"|'((?:\\.|[^'\\])*)'|([^)\s]*))\s*\)\s*$/.exec(css ?? '');if (!m) return null;return (m[1] ?? m[2] ?? m[3] ?? '').replace(/\\(.)/g, '$1');}