Skip to content

Commit

Permalink
fix: command not found on empty arg (#887) (#888)
Browse files Browse the repository at this point in the history
when `topicSeparator` is a space and an empty string arg is given,
the searched command ID had an extra colon:

example:

```bash
set FOO=""
cli cmd ${FOO} --bar
```

result: command not found "cmd"

root cause: incorrect parsing in `standardizeIDFromArgv`,
which for the above example returned `cmd:` as the command ID.

Co-authored-by: Roy Razon <roy@razon.info>
  • Loading branch information
mdonnalley and royra authored Nov 30, 2023
1 parent b7124bf commit a8ca6cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/help/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function collateSpacedCmdIDFromArgs(argv: string[], config: IConfig): string[] {

const final: string[] = []
const idPresent = (id: string) => ids.has(id)
const finalizeId = (s?: string) => (s ? [...final, s].join(':') : final.join(':'))
const finalizeId = (s?: string) => (s ? [...final, s] : final).filter(Boolean).join(':')

const hasArgs = () => {
const id = finalizeId()
Expand Down
6 changes: 6 additions & 0 deletions test/help/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ describe('util', () => {
expect(actual).to.deep.equal(['foo:bar', '--baz'])
})

test.it('should return standardized id when topic separator is a space', () => {
config.topicSeparator = ' '
const actual = standardizeIDFromArgv(['foo', '', '--baz'], config)
expect(actual).to.deep.equal(['foo', '', '--baz'])
})

test
.stub(util, 'collectUsableIds', (stub) => stub.returns(new Set(['foo', 'foo:bar'])))
.it('should return standardized id when topic separator is a space', () => {
Expand Down

0 comments on commit a8ca6cc

Please sign in to comment.