fix(studio): the copied render command carries no composition text a shell can run (#8012)

* fix(studio): the copied render command carries no composition text a shell can run

The Variables panel's "Copy render command" put every variable value inline,
quoted for POSIX shells only. A shared project's author chooses those values,
so in PowerShell, cmd.exe (including npx.cmd's re-parse) or fish a default
such as `x'; calc.exe; '` ran as commands when the command was pasted.

The command is now fixed text: `npx hyperframes render -c <composition>
--variables-file .hyperframes/render-variables.json`. Copying it saves the
previewed values to that file through a new PUT /projects/:id/render-variables
route, which refuses a link standing in for .hyperframes and replaces, rather
than writes through, a link at the file itself. A composition path that is not
one plain word in every shell (letters, digits, `_ . / -`) gets no command.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(scripts): the comment checker skips a template nested in a substitution

stripLiterals ended a template literal at the first backtick, including one
that opens a nested template inside `${...}`. On a line such as
`'${value.replace(/'/g, `'\\''`)}'` that left a backtick unmatched, so
scanCLike read the rest of the file as one template and counted none of its
comments. The ratchet then measured VariablesPanel.tsx on main at 1 comment
line instead of 31 and failed any change that removed that line.

A `${...}` is now scanned as code: strings, regexes and templates inside it
are skipped, and its closing brace returns to the outer template.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(studio-server): read the replaced render-variables record through one no-follow descriptor

The link test checked the record with lstat and then read it by path, two
lookups CodeQL reports as a file-system race. Opening it once with O_NOFOLLOW
fails if a link is still there and reads the file that open checked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Andy Cheigh
2026-11-17 05:05:28 +00:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 8239fe4702
commit 19743ea094
10 changed files with 444 additions and 25 deletions
+40 -6
View File
@@ -191,8 +191,46 @@ function literalEnd(line, start, regex) {
return -1;
}
// Index just past the literal opening at `i` (string, template or regex), or -1. `before` is the code preceding it.
// A `/` after a value, `<`, `++` or `--` is division or a tag (`a / b`, `</p>`, `i++ / 2`).
function literalAt(line, i, before) {
const ch = line[i];
if (ch === "`") return templateEnd(line, i);
// ponytail: `return /re/` reads as division; add a keyword check if that ever hides a comment.
const regex = ch === "/" && !/(?:[\w$)\]<]|\+\+|--)$/.test(before.trimEnd());
const end = regex || `"'`.includes(ch) ? literalEnd(line, i, regex) : -1;
// A regex never closes on a comment opener: this `/` is division, e.g. continued from the line above.
return regex && (line[end] === "/" || line[end] === "*") ? -1 : end;
}
// A `${…}` holds code, so a backtick in it opens a nested template rather than closing this one.
function templateEnd(line, start) {
for (let i = start + 1; i < line.length; i++) {
if (line[i] === "\\") i++;
else if (line[i] === "`") return i + 1;
else if (line[i] === "$" && line[i + 1] === "{") {
const end = substitutionEnd(line, i + 2);
if (end === -1) return -1;
i = end - 1;
}
}
return -1;
}
function substitutionEnd(line, start) {
let depth = 0;
for (let i = start; i < line.length; ) {
const ch = line[i];
if (ch === "}" && depth === 0) return i + 1;
if (ch === "{") depth++;
if (ch === "}") depth--;
const end = literalAt(line, i, line.slice(start, i));
i = end === -1 ? i + 1 : end;
}
return -1;
}
/** stripStrings for C-like code, plus regex literals, so `/["'`]/` opens no string or template.
* A `/` after a value, `<`, `++` or `--` is division or a tag (`a / b`, `</p>`, `i++ / 2`).
* Stops at the first comment. */
function stripLiterals(line) {
let out = "";
@@ -200,11 +238,7 @@ function stripLiterals(line) {
const ch = line[i];
const comment = ch === "/" && (line[i + 1] === "/" || line[i + 1] === "*");
if (comment) return out + line.slice(i);
// ponytail: `return /re/` reads as division; add a keyword check if that ever hides a comment.
const regex = ch === "/" && !/(?:[\w$)\]<]|\+\+|--)$/.test(out.trimEnd());
let end = regex || `"'\``.includes(ch) ? literalEnd(line, i, regex) : -1;
// A regex never closes on a comment opener: this `/` is division, e.g. continued from the line above.
if (regex && (line[end] === "/" || line[end] === "*")) end = -1;
const end = literalAt(line, i, out);
if (end === -1) {
out += ch;
i++;
+11
View File
@@ -44,6 +44,17 @@ test("quotes inside a regex literal open no string, so later comments still coun
assert.equal(measure(source, ".ts").comment, 4);
});
test("a template nested in a substitution does not end the outer template, so later comments still count", () => {
const source = [
"const quoted = `'${value.replace(/'/g, `'\\\\''`)}'`;",
"// one",
"const label = `${what} copied`; // two",
'const deep = `a${b ? `c${d}` : "}"}e`;',
"// three",
].join("\n");
assert.equal(measure(source, ".ts").comment, 3);
});
test("a JSX closing tag's slash opens no regex", () => {
assert.equal(measure("const a = <p>x</p>; // c\n", ".tsx").comment, 1);
assert.equal(measure("const a = <a>x</a>{/* note */};\n", ".tsx").comment, 1);