fix(studio-server): a folder-relative url() in a minified page style follows a rename

This commit is contained in:
Miguel Ángel
2026-11-25 04:28:56 +00:00
parent 73b26a0d5e
commit a2e0a90a1b
2 changed files with 16 additions and 1 deletions
@@ -409,7 +409,7 @@ export function referenceRewriter(
const MAX_REST = 256;
const restAfter = (text: string, end: number) =>
/^[^"'`<>\r\n]*/.exec(text.slice(end, end + MAX_REST))![0];
const REFERENCE_END = /^(?:$|\)(?=$|[\s;,])|[?#]|,\s|\s+\d+(?:\.\d+)?[wx](?![\w.]))/;
const REFERENCE_END = /^(?:$|\)(?=$|[\s;,}!)/])|[?#]|,\s|\s+\d+(?:\.\d+)?[wx](?![\w.]))/;
function reaches(targets: ReadonlySet<string>, path: string): boolean {
for (let i = 0; i <= path.length; i++)
@@ -838,4 +838,19 @@ describe("renaming a folder over the route", () => {
'url("old clips/a.png") url(takes/a.png)',
);
});
// fails without the fix: a page's minified <style> ended a url() with `}`, so its folder reading never matched.
it("in HTML follows a folder-relative url() in a minified style", async () => {
const project = mkdtempSync(join(tmpdir(), "hf-rename-refs-"));
dirs.push(project);
mkdirSync(join(project, "assets", "clips"), { recursive: true });
writeFileSync(join(project, "assets", "clips", "a.png"), "x");
const style = (folder: string) =>
`<style>.a{background:url(${folder}/a.png)}.b{background:url(${folder}/a.png)!important}` +
`.c{background:image-set(url(${folder}/a.png) 1x)}</style>`;
writeFileSync(join(project, "assets", "page.html"), style("clips"));
const response = await renameIn(project, "assets/clips", "assets/takes");
expect(response.status).toBe(200);
expect(readFileSync(join(project, "assets", "page.html"), "utf8")).toBe(style("takes"));
});
});