Code Monkey home page Code Monkey logo

Comments (3)

shadowspawn avatar shadowspawn commented on July 28, 2024

yargs-parser does not support escaping embedded quotes, but it does support nesting quotes. So you can have " inside ' quotes.

I am not sure what quoting you would want for the slash and newline, but this quoting at least reads everything after the -d as the option value:

import parser from 'yargs-parser'
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"}'`;
const argv = parser(curl);
console.log(argv);
% node index.mjs
{
  _: [ 'curl', '"https://api.example.com/data"' ],
  X: 'POST',
  H: 'Content-Type: application/json',
  d: '{"key": "This string has an escaped backslash: \\\\ and a newline: \\\\n"}'
}

from yargs-parser.

jettdc avatar jettdc commented on July 28, 2024

Unfortunately these strings are coming from user input, and since the mentioned curl command is a valid curl command/bash/input, I need to be able to support it

Is there a reason it doesn't support escaping embedded quotes?

from yargs-parser.

shadowspawn avatar shadowspawn commented on July 28, 2024

If you can access the command after it is parsed by the shell into separate arguments then you avoid the problem that different shells/platforms and yargs split up command-line into arguments in different ways. (I realise this may not be possible in your use case, but I thought worth mentioning as a general approach.)

Related: #300 #385

Is there a reason it doesn't support escaping embedded quotes?

I suspect just hasn't come up enough.

A package I have used for some quoting work is: https://www.npmjs.com/package/shell-quote

from yargs-parser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.