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

Trailing and leading quotes #222

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
move quote handling from index.js to tokenizer
  • Loading branch information
juergba committed Nov 17, 2019
commit 41c9aafbe1c3f08a155100ed3cf885710226efc4
15 changes: 9 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,16 @@ function parse (args, opts) {
}

function processValue (key, val) {
// strings may be quoted, clean this up as we assign values.
if (typeof val === 'string' &&
(val[0] === "'" || val[0] === '"') &&
val[val.length - 1] === val[0]
) {
val = val.substring(1, val.length - 1)
if (typeof val === 'string' && val.startsWith('\\-')) {
val = val.substring(1, val.length)
}
// strings may be quoted, clean this up as we assign values.
// if (typeof val === 'string' &&
// (val[0] === "'" || val[0] === '"') &&
// val[val.length - 1] === val[0]
// ) {
// val = val.substring(1, val.length - 1)
// }

// handle parsing boolean arguments --foo=true --bar false.
if (checkAllAliases(key, flags.bools) || checkAllAliases(key, flags.counts)) {
Expand Down
3 changes: 3 additions & 0 deletions lib/tokenize-arg-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ module.exports = function (argString) {
// don't split the string if we're in matching
// opening or closing single and double quotes.
if (c === opening) {
if (!args[i]) args[i] = ''
opening = null
continue
} else if ((c === "'" || c === '"') && !opening) {
opening = c
continue
}

if (!args[i]) args[i] = ''
Expand Down