Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(cli): reject an empty flag value instead of resolving it to cwd

EtienneLescotf4f40f112af5
diff --git a/electron/cli/args.test.ts b/electron/cli/args.test.ts
index 05b3dff73..2b1f5fb6d 100644
--- a/electron/cli/args.test.ts
+++ b/electron/cli/args.test.ts
@@ -172,6 +172,17 @@ describe("parseCliArgs", () => {
expect(parse(["sources", "--out"])).toMatchObject({ kind: "error" });
});
+ it("rejects an empty flag value rather than resolving it to cwd", () => {
+ // `openscreen sources -o "$OUT"` with OUT unset arrives as an empty
+ // argument. resolvePath would turn it into cwd, which only fails later as
+ // EISDIR from the write; the omitted-value spelling is the same mistake and
+ // must get the same answer.
+ expect(parse(["sources", "-o", ""])).toMatchObject({ kind: "error" });
+ // takeValue is shared, so every flag that takes a value gets this.
+ expect(parse(["pack", "demo.openscreen", "--out", ""])).toMatchObject({ kind: "error" });
+ expect(parse(["export", "demo.openscreen", "-o", ""])).toMatchObject({ kind: "error" });
+ });
+
it("parses pack", () => {
expect(parse(["pack", "demo.openscreen", "--out", "bundle"])).toMatchObject({
kind: "pack",
diff --git a/electron/cli/args.ts b/electron/cli/args.ts
index a3aee97c0..d9e33819e 100644
--- a/electron/cli/args.ts
+++ b/electron/cli/args.ts
@@ -107,7 +107,14 @@ or pass --duration.
function takeValue(argv: string[], i: number, flag: string): [string, number] {
const next = argv[i + 1];
- if (next === undefined || next.startsWith("--")) {
+ // "" is rejected alongside a missing value: an unset variable in a wrapper
+ // (`openscreen sources -o "$OUT"`) reaches us as an empty argument, and every
+ // caller here feeds the result to resolvePath, where path.resolve(cwd, "")
+ // returns cwd. That turns a typo into a directory path, which then fails much
+ // later as EISDIR from the write — after the work is done and discarded —
+ // instead of as the parse error the same mistake gets when the value is
+ // omitted entirely.
+ if (next === undefined || next === "" || next.startsWith("--")) {
throw new Error(`${flag} requires a value`);
}
return [next, i + 1];