Skip to content

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

Open
@jbms

Description

@jbms

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions