Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/utils/generate/parseParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions test/unit/utils/generate/parseParams.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Loading