From ea59160e779ada33a11fbd0a4bdcfd7a158a8513 Mon Sep 17 00:00:00 2001 From: Ryooooooga Date: Thu, 30 Nov 2023 13:26:51 +0900 Subject: [PATCH 1/3] fix: fix `escapeArg` --- src/command.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/command.ts b/src/command.ts index 17f3c26..09e0ed7 100644 --- a/src/command.ts +++ b/src/command.ts @@ -867,10 +867,10 @@ function buildEnv(env: Record) { export function escapeArg(arg: string) { // very basic for now - if (/^[A-Za-z0-9]*$/.test(arg)) { + if (/^[A-Za-z0-9]+$/.test(arg)) { return arg; } else { - return `'${arg.replace("'", `'"'"'`)}'`; + return `'${arg.replaceAll("'", `'"'"'`)}'`; } } From 9f063c2092edfa2a4d48a5d1984a5238f024c83d Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sun, 17 Dec 2023 10:54:10 +0100 Subject: [PATCH 2/3] Add test --- src/command.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/command.test.ts diff --git a/src/command.test.ts b/src/command.test.ts new file mode 100644 index 0000000..ad99bdd --- /dev/null +++ b/src/command.test.ts @@ -0,0 +1,7 @@ +import { escapeArg } from "./command.ts"; +import { assertEquals } from "./deps.test.ts"; + +Deno.test("escapes arg", () => { + assertEquals(escapeArg("hello"), "hello"); + assertEquals(escapeArg("'abc'"), `''"'"'abc'"'"''`); +}); From 3d70ab4b4c22317b76bde18dce5639af21959e2c Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sun, 17 Dec 2023 10:55:14 +0100 Subject: [PATCH 3/3] Another test --- src/command.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/command.test.ts b/src/command.test.ts index ad99bdd..d326bbf 100644 --- a/src/command.test.ts +++ b/src/command.test.ts @@ -3,5 +3,6 @@ import { assertEquals } from "./deps.test.ts"; Deno.test("escapes arg", () => { assertEquals(escapeArg("hello"), "hello"); + assertEquals(escapeArg(""), "''"); assertEquals(escapeArg("'abc'"), `''"'"'abc'"'"''`); });