Repository navigation
Conversation
camelcase() in lib/option.js assumed every segment produced by
str.split('-') is non-empty, indexing word[0] directly. An option flags
string with a doubled hyphen (an easy typo, e.g. '--dry--run' instead of
'--dry-run') or a trailing hyphen produces an empty segment, so word[0]
is undefined and .toUpperCase() throws a raw TypeError.
This crash happens synchronously inside .option()/.addOption(), so it is
not a CommanderError and is not caught by exitOverride().
Use word.charAt(0), which returns '' for an empty segment, so the empty
segment is skipped ('--foo--bar' maps to attribute name 'fooBar').
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.option('--foo--bar <val>')(an easy typo of--foo-bar, e.g.--dry--run) currently crashes with an uncaughtTypeError: Cannot read properties of undefined (reading 'toUpperCase')instead of being handled by commander.camelcase()inlib/option.jsindexesword[0]afterstr.split('-'), which isundefinedfor the empty segment produced by a doubled or trailing hyphen.splitOptionFlags()already rejects malformed dash prefixes (e.g.---triple) but not an embedded double hyphen, so this input reachescamelcase()unvalidated.TypeError, not aCommanderError, so it also bypassesexitOverride().word.charAt(0)instead ofword[0], which returns''for an empty segment, so the segment is skipped instead of crashing (--foo--bargives attribute namefooBar).Test plan
tests/option.attributeName.test.jscovering doubled hyphen, trailing hyphen, and negated-option doubled-hyphen cases. All 3 fail without the fix and pass with it.node --test: 1375 passing, 0 failing, 1 skipped (previously 1372 passing).prettier --checkclean on the changed files.🤖 Generated with Claude Code