Skip to content

Commit

Permalink
fix: escapeArg was not escaping multiple quotes (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryooooooga authored Dec 17, 2023
1 parent fc2ea78 commit e0386dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/command.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { escapeArg } from "./command.ts";
import { assertEquals } from "./deps.test.ts";

Deno.test("escapes arg", () => {
assertEquals(escapeArg("hello"), "hello");
assertEquals(escapeArg(""), "''");
assertEquals(escapeArg("'abc'"), `''"'"'abc'"'"''`);
});
4 changes: 2 additions & 2 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -875,10 +875,10 @@ function buildEnv(env: Record<string, string | undefined>) {

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("'", `'"'"'`)}'`;
}
}

Expand Down

0 comments on commit e0386dd

Please sign in to comment.