Skip to content

Commit

Permalink
Fix boolean regexp (denoland/std#582)
Browse files Browse the repository at this point in the history
  • Loading branch information
justjavac authored and ry committed Sep 4, 2019
1 parent 9533a03 commit be9aaa6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions flags/bool_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,14 @@ test(function booleanParsingFalse(): void {

assertEquals(parsed.boool, false);
});

test(function booleanParsingTrueLike(): void {
const parsed = parse(["-t", "true123"], { boolean: ["t"] });
assertEquals(parsed.t, true);

const parsed2 = parse(["-t", "123"], { boolean: ["t"] });
assertEquals(parsed2.t, true);

const parsed3 = parse(["-t", "false123"], { boolean: ["t"] });
assertEquals(parsed3.t, true);
});
2 changes: 1 addition & 1 deletion flags/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export function parse(
) {
setArg(key, args[i + 1], arg);
i++;
} else if (args[i + 1] && /true|false/.test(args[i + 1])) {
} else if (args[i + 1] && /^(true|false)$/.test(args[i + 1])) {
setArg(key, args[i + 1] === "true", arg);
i++;
} else {
Expand Down

0 comments on commit be9aaa6

Please sign in to comment.