Skip to content

fix: keep params with an empty value - #2299

Open
priyanthants wants to merge 1 commit into
asyncapi:masterfrom
priyanthants:fix/param-empty-value
Open

priyanthants wants to merge 1 commit into
asyncapi:masterfrom
priyanthants:fix/param-empty-value

Conversation

@priyanthants

Copy link
Copy Markdown

Description

paramParser (used by asyncapi generate ... --param name=value) parsed each input with:

const [paramName, paramValue] = input.split(/=(.+)/, 2);

The (.+) in that regex requires at least one character after =, so an input with an empty value — name= — does not match the split pattern. The result is that the whole param is dropped:

paramParser(['name='])          // → {}            (expected { name: '' })
paramParser(['name=value'])     // → { name: 'value' }   ✅
paramParser(['url=a=b'])        // → { url: 'a=b' }       ✅

So passing --param foo= (intentionally setting an empty value, e.g. to blank out a template parameter) is silently ignored, with no error.

Fix

Split on the first = using indexOf / slice. This keeps values that contain = and preserves params whose value is empty:

const separatorIndex = input.indexOf('=');
const paramName = input.slice(0, separatorIndex);
const paramValue = input.slice(separatorIndex + 1);

Tests

The existing test titled "should handle input with trailing equals (no capture after =)" actually passed name=value (a non-empty value), so it never exercised the case its title described — it gave false confidence while the bug remained. It now passes name= and asserts { name: '' }.

Verified locally: the updated parseParams suite passes (20/20), and the new assertion fails against the old implementation ({ 'name=': undefined }), confirming it covers the bug. eslint clean on both changed files.


Found by reading the code; no pre-existing issue. Happy to open one to track it if you prefer.

AI disclosure: produced with assistance from Claude (Anthropic), credited via a Co-authored-by: trailer on the commit. I reviewed, ran, and verified the change myself.

`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 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Sep 19, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 5110441

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To Triage

Development

Successfully merging this pull request may close these issues.

1 participant