From 51104416f0e39b0aa7fe907fe6ba2f4d083c5b94 Mon Sep 17 00:00:00 2001 From: Priyanthan Date: Sat, 19 Sep 2026 18:05:01 +0000 Subject: [PATCH] fix: keep params with an empty value `paramParser` split each `--param name=value` input with `input.split(/=(.+)/, 2)`. The `(.+)` requires at least one character after `=`, so an input with an empty value such as `name=` did not match and the param was dropped entirely: `paramParser(['name='])` returned `{}` instead of `{ name: '' }`. Passing `--param foo=` was therefore silently ignored. Split on the first `=` with `indexOf` instead, which preserves values that contain `=` and keeps params whose value is empty. The existing "trailing equals" test asserted this case but was passing `name=value` (a non-empty value), so it never exercised the bug. It now uses `name=` and expects `{ name: '' }`. Co-authored-by: Claude Opus 4.8 --- src/utils/generate/parseParams.ts | 7 ++++++- test/unit/utils/generate/parseParams.test.ts | 7 +++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/utils/generate/parseParams.ts b/src/utils/generate/parseParams.ts index 10e4348b8..ef830b156 100644 --- a/src/utils/generate/parseParams.ts +++ b/src/utils/generate/parseParams.ts @@ -7,7 +7,12 @@ export function paramParser(inputs?: string[]) { if (!input.includes('=')) { throw new Error(`Invalid param ${input}. It must be in the format of --param name1=value1 name2=value2 `); } - const [paramName, paramValue] = input.split(/=(.+)/, 2); + // Split on the first `=` only, so values may contain `=` and may be empty + // (e.g. `name=` sets an empty value). A capturing-group regex split dropped + // params with an empty value entirely. + const separatorIndex = input.indexOf('='); + const paramName = input.slice(0, separatorIndex); + const paramValue = input.slice(separatorIndex + 1); params[String(paramName)] = paramValue; } return params; diff --git a/test/unit/utils/generate/parseParams.test.ts b/test/unit/utils/generate/parseParams.test.ts index 1fa7f0ada..16f26d320 100644 --- a/test/unit/utils/generate/parseParams.test.ts +++ b/test/unit/utils/generate/parseParams.test.ts @@ -27,10 +27,9 @@ describe('parseParams utilities', () => { expect(result).to.deep.equal({ url: 'http://example.com?foo=bar' }); }); - it('should handle input with trailing equals (no capture after =)', () => { - // The regex (.+) requires at least one char after =, so 'name=' won't split properly - const result = paramParser(['name=value']); - expect(result).to.have.property('name', 'value'); + it('should parse a param with an empty value (trailing equals)', () => { + const result = paramParser(['name=']); + expect(result).to.deep.equal({ name: '' }); }); it('should throw error for input without equals sign', () => {