Skip to content

Commit 62a6746

Browse files
committed
fix(tui): preserve quoted Windows paths
1 parent b9dd1ed commit 62a6746

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/tui.mjs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,20 @@ const ask = (rl) => new Promise((res) => rl.question(PROMPT(), res));
6666
export function splitCommandLine(line) {
6767
const parts = [];
6868
let value = "", quote = null, escaped = false, started = false;
69-
for (const char of String(line)) {
69+
const input = String(line);
70+
for (let i = 0; i < input.length; i++) {
71+
const char = input[i];
7072
if (escaped) {
7173
value += char;
7274
escaped = false;
7375
started = true;
7476
} else if (char === "\\" && quote !== "'") {
77+
const next = input[i + 1];
78+
if (quote === '"' && next !== '"' && next !== "\\") {
79+
value += char;
80+
started = true;
81+
continue;
82+
}
7583
escaped = true;
7684
started = true;
7785
} else if (quote) {

test/tui.test.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ test("TUI command parsing supports escaped whitespace and empty arguments", () =
1919
]);
2020
});
2121

22+
test("TUI command parsing preserves Windows paths inside double quotes", () => {
23+
assert.deepEqual(splitCommandLine('/run "C:\\Users\\mosh\\script.mosh"'), [
24+
"/run",
25+
"C:\\Users\\mosh\\script.mosh",
26+
]);
27+
});
28+
2229
test("TUI command parsing rejects incomplete quoting", () => {
2330
assert.throws(() => splitCommandLine('/coinpay --description "unfinished'), /unterminated/);
2431
assert.throws(() => splitCommandLine("/ugig trailing\\"), /trailing escape/);

0 commit comments

Comments
 (0)