String values in config files that contain embedded quotes are not handled correctly
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- javascript, typescript
- Domain
- cli
Research direction
Review lib/yargs-parser.ts at line 608 and the .config/process.argv parsing entry points. Reproduce the JSON.stringify example, then verify that already-split values preserve embedded quotes while only unsplit strings receive shell-style quote handling.
Written by the indexing model from the issue text.
Description
If a config object specified via the .config option to yargs contains a value that starts and ends with quotes, yargs strips those quotes, due to this code here:
That seems like confusing, and undesirable behavior, and makes it difficult to pass values containing embedded quotes.
For example:
console.log(require('yargs').config({a: JSON.stringify('hello')}).parse());
This prints:
{ _: [], a: 'hello', '$0': 'yargs-bug.js' }
But I would expect it to instead print:
{ _: [], a: '"hello"', '$0': 'yargs-bug.js' }
I would suggest that when parsing already-split arguments, e.g. from process.argv, or when processing a config file, quotes should never be stripped, and no additional splitting should ever occur. The only time stripping of quotes should happen is when parsing an unsplit string. In that case, the string should be parsed into an array of strings using shell-style parsing, and then parsing should proceed using the resultant array, and do no further splitting or quote handling.
- Dominant language
- JavaScript
- Stars
- 519
- Forks
- 129
- Avg merge
- 1h 34m
- Merged PRs (30d)
- 1
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from yargs/yargs-parser
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
yargs/yargs-parser#518 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 48/100
yargs/yargs-parser#506 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
yargs/yargs-parser#484 · 3 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 38/100
yargs/yargs-parser#468 · 1 comment ·
-
bug p2
Difficulty 3/5 1-2 days Newbie friendliness 55/100
yargs/yargs-parser#445 · 1 comment ·
All issues in yargs/yargs-parser
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
sugarlabs/musicblocks#8847 ·