Files
hyperframes/packages/studio/src/utils/studioSelectionSnapshot.test.ts
Miguel Ángel 621ddd4693 fix(studio): stop file names with %, apostrophes or $ from breaking Studio (#5156)
* fix(studio): serve files whose name has a bare percent sign

A browser sends src="100%.png" with the % unescaped, and decoding the whole path threw, so Studio answered 500. Only well-formed escapes are decoded now.

* fix(cli): serve files with a bare percent sign from the check and snapshot server

One shared decode rule for request paths; the image thumbnail route's malformed-escape 400 could no longer fire, so a name that is not a file is a 404.

* fix(cli): name a failed file with a bare percent sign in check

* fix(studio): keep apostrophes and dollar signs in file names when editing attributes

An attribute value is matched by its own quote kind, so src="it's.png" is replaced instead of duplicated, and every insert uses a function replacer, so $1 or $& in a file name is written as is.

* fix(studio): rename references spelled with %20 or & and read quoted media sources

WIP: not yet tested; see the resume note.

* fix(studio): match whole attribute names when editing media sources

* fix(studio): compare decoded names and escape replacement references

* fix(studio): preserve file references across URL and string consumers

* docs: clarify raw file references and URL fields

* fix(studio): keep raw path identity distinct from URL spelling

* fix: share attribute grammar and decode media URLs at their readers

* fix: preserve local filename identity in HTML URL output

* fix: decode entity references before rename candidate matching

* style: format rename entity handling and regressions

* fix: preserve platform file identity when renaming references

* fix(core): decode CSS escapes before rebasing asset URLs

* fix(core): consume CSS continuations before URL encoding

* fix(core): preserve CSS URL identity and escape rebased suffixes

* fix(core): express CSS suffix controls with Unicode categories

* fix(core): preserve URL backslash identity while rebasing

* test(core): respect platform backslash filename semantics

* fix(studio): a dropped file with %, # or ? in its name loads, and an encoded reference renames

* fix(studio): read an authored src as a URL so dropped files with spaces, %, # or ? load

* fix(studio): media routes find files named with ? or #, and the probe reads a src as a URL

* fix(studio-server): one rule for request file paths, so loudness finds files named with %, # or ?

* chore: drop the design note from the change

* fix(core): rename replaced clips whose src is URL-encoded
2026-10-08 16:37:49 +00:00

79 lines
2.6 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { buildStudioSelectionSnapshot } from "./studioSelectionSnapshot";
import type { DomEditSelection } from "../components/editor/domEditing";
describe("buildStudioSelectionSnapshot", () => {
it("serializes a DOM edit selection without the live HTMLElement", () => {
const selection = {
element: { tagName: "H1" } as HTMLElement,
id: null,
hfId: "hero-title",
selector: ".title",
selectorIndex: 0,
label: "Hero title",
tagName: "h1",
sourceFile: "index.html",
compositionPath: "index.html",
isCompositionHost: false,
isInsideLockedComposition: false,
boundingBox: { x: 10, y: 20, width: 300, height: 64 },
textContent: "Launch faster",
dataAttributes: { "data-hf-id": "hero-title" },
inlineStyles: { color: "white" },
computedStyles: { "font-size": "48px" },
textFields: [],
capabilities: { canSelect: true, canEditStyles: true },
} as DomEditSelection;
const snapshot = buildStudioSelectionSnapshot({
projectId: "demo",
selection,
currentTime: 1.25,
});
expect(snapshot).toMatchObject({
schemaVersion: 1,
projectId: "demo",
compositionPath: "index.html",
sourceFile: "index.html",
currentTime: 1.25,
target: { hfId: "hero-title", selector: ".title", selectorIndex: 0 },
thumbnailUrl:
"/api/projects/demo/thumbnail/index.html?t=1.25&format=png&output=source&selector=.title&selectorIndex=0",
});
expect(JSON.stringify(snapshot)).not.toContain("HTMLElement");
expect(snapshot).not.toHaveProperty("element");
});
it("links a selection inside a sub-composition to its own thumbnail", () => {
const snapshot = buildStudioSelectionSnapshot({
projectId: "demo",
selection: {
element: { tagName: "H1" } as HTMLElement,
id: null,
hfId: "intro-title",
selector: ".title",
selectorIndex: 0,
label: "Intro title",
tagName: "h1",
sourceFile: "compositions/intro #1.html",
compositionPath: "compositions/intro #1.html",
isCompositionHost: false,
isInsideLockedComposition: false,
boundingBox: { x: 0, y: 0, width: 10, height: 10 },
textContent: "Intro",
dataAttributes: {},
inlineStyles: {},
computedStyles: {},
textFields: [],
capabilities: { canSelect: true, canEditStyles: true },
} as DomEditSelection,
currentTime: 0,
});
expect(snapshot.thumbnailUrl).toMatch(
/^\/api\/projects\/demo\/thumbnail\/compositions%2Fintro%20%231\.html\?/,
);
});
});