Skip to content

Commit 94a84ee

Browse files
committed
fix(install): accept backslashes and newlines in T3 home paths
1 parent 758d773 commit 94a84ee

2 files changed

Lines changed: 18 additions & 11 deletions

File tree

‎scripts/install.sh‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,11 @@ case "$(uname -m)" in
134134
*) fail "unsupported architecture $(uname -m)" ;;
135135
esac
136136
command -v tar >/dev/null 2>&1 || fail "tar is required"
137+
# Hash stdin so filename escaping cannot add a backslash before the digest.
137138
if command -v sha256sum >/dev/null 2>&1; then
138-
checksum() { sha256sum "$1" | cut -d' ' -f1; }
139+
checksum() { sha256sum < "$1" | cut -d' ' -f1; }
139140
elif command -v shasum >/dev/null 2>&1; then
140-
checksum() { shasum -a 256 "$1" | cut -d' ' -f1; }
141+
checksum() { shasum -a 256 < "$1" | cut -d' ' -f1; }
141142
else
142143
fail "sha256sum or shasum is required"
143144
fi

‎scripts/install.test.ts‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ import * as NodePath from "node:path";
99
import { describe, expect, it } from "vite-plus/test";
1010

1111
describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("installer terminal", () => {
12-
it.each([false, true])(
13-
"preserves download and install behavior (HTTP failure: %s)",
14-
async (fail) => {
12+
it.each([
13+
{ fail: false, homeName: "home" },
14+
{ fail: true, homeName: "home" },
15+
{ fail: false, homeName: "home\\data" },
16+
{ fail: false, homeName: "home\ndata" },
17+
])(
18+
"preserves download and install behavior (HTTP failure: $fail, home: $homeName)",
19+
async ({ fail, homeName }) => {
1520
const root = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-install-progress-"));
21+
const t3Home = NodePath.join(root, homeName);
1622
const version = "1.2.3";
1723
const stem = `t3-${version}-linux-${HostProcess.Architecture.defaultValue()}`;
1824
const archiveName = `${stem}.tar.gz`;
@@ -60,7 +66,7 @@ describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("installer term
6066
TERM: "xterm",
6167
NO_COLOR: "1",
6268
T3CODE_VERSION: version,
63-
T3CODE_HOME: NodePath.join(root, "home"),
69+
T3CODE_HOME: t3Home,
6470
T3CODE_INSTALL_BIN_DIR: NodePath.join(root, "bin"),
6571
T3CODE_RELEASE_BASE_URL: `http://127.0.0.1:${address.port}`,
6672
},
@@ -80,15 +86,15 @@ describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("installer term
8086
child.on("error", reject);
8187
child.on("close", resolve);
8288
});
83-
const versions = NodePath.join(root, "home/runtime/versions");
89+
const versions = NodePath.join(t3Home, "runtime/versions");
8490
if (fail) {
8591
expect(code).not.toBe(0);
8692
expect(output).toContain("500");
8793
expect(output).not.toContain("100%");
8894
expect(output).not.toContain("Installed T3 Code");
8995
expect(await NodeFSP.readdir(versions)).toEqual([]);
9096
} else {
91-
expect(code).toBe(0);
97+
expect(code, output).toBe(0);
9298
expect(sawPartialProgress).toBe(true);
9399
expect(output).toContain("100%");
94100
expect(output).toContain("0.1 / 0.1 MB");
@@ -102,9 +108,9 @@ describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("installer term
102108
}).trim(),
103109
).toBe("t3 v1.2.3");
104110
expect(await NodeFSP.readdir(versions)).toEqual([version]);
105-
expect(
106-
await NodeFSP.readFile(NodePath.join(root, "home/runtime/launchers"), "utf8"),
107-
).toBe(`${NodePath.join(root, "bin/t3")}\n`);
111+
expect(await NodeFSP.readFile(NodePath.join(t3Home, "runtime/launchers"), "utf8")).toBe(
112+
`${NodePath.join(root, "bin/t3")}\n`,
113+
);
108114
}
109115
} finally {
110116
if (child.exitCode === null) child.kill();

0 commit comments

Comments
 (0)