Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String values in config files that contain embedded quotes are not handled correctly #385

Open
jbms opened this issue May 19, 2021 · 1 comment
Labels

Comments

@jbms
Copy link

jbms commented May 19, 2021

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:

// strings may be quoted, clean this up as we assign values.

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.

@rogatec
Copy link

rogatec commented Mar 23, 2022

Are there any news how to solve this?
I have a quite similar issue - via the config method I am reading a JSON file, which has some properties with dashes, for e.g. "X-MyPropety": "1",

Those properties will be duplicated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants