fix(config): harden CLI option and config-file parsing against bad input#124
Merged
fix(config): harden CLI option and config-file parsing against bad input#124
Conversation
- Type-guard --token and --cookie validation so passing null or a non-string produces a clean validation error instead of a TypeError on .trim() - Surface a stderr warning when ~/.confluence-cli/config.json fails to parse, instead of silently returning null and falling through to "No configuration found!" — making corrupted-config debugging straightforward
github-actions Bot
pushed a commit
that referenced
this pull request
Apr 27, 2026
## [1.33.2](v1.33.1...v1.33.2) (2026-04-27) ### Bug Fixes * **config:** harden CLI option and config-file parsing against bad input ([#124](#124)) ([1ee18ef](1ee18ef))
|
🎉 This PR is included in version 1.33.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
8 tasks
pchuri
added a commit
that referenced
this pull request
Apr 27, 2026
…trings (#128) Follow-up to #124, applying the same defensive pattern to the rest of validateCliOptions and the providedValues construction in initConfig: - domain, email, apiPath, protocol, authType: type-check before calling string methods (trim/startsWith/toLowerCase/includes), so non-string truthy inputs (e.g. numeric values from programmatic callers) surface a clean validation error instead of a TypeError - The early authType normalization in initConfig (`.trim().toLowerCase()` before validateCliOptions runs) is also guarded so the crash cannot occur before validation gets a chance to report it - Adds regression tests covering domain, apiPath, protocol, and authType
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.
Description
Two small robustness fixes in
lib/config.js:--token/--cookieno longer crash on non-string values.validateCliOptionspreviously called.trim()after only an!== undefinedguard, sonullor numeric values produced a confusingTypeError: Cannot read properties of null (reading 'trim')instead of the intended--token cannot be emptyvalidation error. Both fields now type-guard before trimming.~/.confluence-cli/config.jsonnow reports the actual parse error.readConfigFile()previously caught any read/parse failure and returnednull, which fell through to a generic "No configuration found! Please run "confluence init"" message — masking the real cause. We now log a yellow warning naming the file and the underlying error before returningnull, so the next "No configuration found!" line still fires but the user can see why.Type of Change
Testing
npm test— 326/326 pass (5 new tests added)npm run lint— clean--token null,--tokennumeric,--cookie nullwith cookie auth, whitespace-only--tokenregression guard, and invalid-JSON config file warning pathChecklist
Additional Context
Behavior is unchanged for valid inputs.
nulland non-string--token/--cookienow produce the same friendlycannot be emptymessage that whitespace-only strings already produced — programmatic callers no longer need to defensively coerce. The corrupted-config warning goes to stderr only when the file exists but cannot be parsed; the no-file case (!fs.existsSync) stays silent as before.