yargs / yargs/yargs-parser

Incorrect parsing of options with escaped quotes

Open
#484 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
519
Forks
129
Avg merge
1h 34m
Merged PRs (30d)
1

Description

trying to parse the string:

const curl = `curl -X POST "https://api.example.com/data" -H "Content-Type: application/json" -d "{\\"key\\": \\"This string has an escaped backslash: \\\\ and a newline: \\\\n\\"}"`;

Which is equivalent to the valid curl command

curl -X POST "https://api.example.com/data" -H "Content-Type: application/json" -d "{\"key\": \"This string has an escaped backslash: \\ and a newline: \\n\"}"

But when I parse it, my args array looks like the following:

_: [
        'curl',
        'https://api.example.com/data',
        'string',
        'has',
        'an',
        'escaped',
        'backslash:',
        '\\\\',
        'and',
        'a',
        'newline:',
        '\\\\n\\"}"'
      ],

Am I missing something or is this a bug?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the exact JavaScript template string and parsing it with yargs-parser, then compare the resulting arguments with the expected curl arguments shown in the issue. Done means escaped quotes, backslashes, and the newline remain within the JSON argument instead of being split into separate arguments.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.