repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

fix(the-system): preserve Windows editor paths

7e35e0185427e3599bc7f8b478472756d3213acb

Oliver Krylow <o.krylow@isp-insoft.de> ·

SSH signature · not checked

Browse filesCompare with HEAD

Changed files (2)

extensions/the-system/__tests__/the-system.test.ts

Modified
328 328 chmodSync(editor, 0o755);
329 329 const previousVisual = process.env.VISUAL;
330 330 const previousEditor = process.env.EDITOR;
331 - process.env.VISUAL = `${process.execPath} ${JSON.stringify(editor)} ${JSON.stringify(log)}`;
331 + process.env.VISUAL = `${JSON.stringify(process.execPath)} ${JSON.stringify(editor)} ${JSON.stringify(log)}`;
332 332 delete process.env.EDITOR;
334 334 const command = createSystemCommand({ sendUserMessage() {} } as never);
358 358 command: "code",
359 359 args: ["--wait", "two words"],
361 + assert.deepEqual(
362 + parseEditorCommand(
363 + '"C:\\Program Files\\Editor\\edit.exe" "C:\\work tree\\file.md"',
364 + ),
366 + command: "C:\\Program Files\\Editor\\edit.exe",
367 + args: ["C:\\work tree\\file.md"],
368 + },
369 + );
361 370 assert.deepEqual(
362 371 editorCandidates("file.md", { VISUAL: "v", EDITOR: "e" }, "linux").slice(

extensions/the-system/open-editor.ts

Modified
90 90 const parts: string[] = [];
91 91 let current = "";
92 92 let quote: "'" | '"' | undefined;
93 - let escaping = false;
95 - for (const char of input) {
96 - if (escaping) {
97 - current += char;
98 - escaping = false;
99 - continue;
100 - }
94 + for (let index = 0; index < input.length; index++) {
95 + const char = input[index];
101 96 if (char === "\\" && quote !== "'") {
102 - escaping = true;
103 - continue;
97 + const next = input[index + 1];
98 + if (next && (/\s/.test(next) || next === '"' || next === "'")) {
99 + current += next;
100 + index++;
101 + continue;
105 104 if ((char === "'" || char === '"') && !quote) {
106 105 quote = char;
118 117 current += char;
120 - if (escaping) current += "\\";
121 119 if (current) parts.push(current);
122 120 return parts;