@@ -59,6 +59,9 @@ export class YargsParser {
59
59
// allow a string argument to be passed in rather
60
60
// than an argv array.
61
61
const args = tokenizeArgString ( argsInput )
62
+ // tokenizeArgString adds extra quotes to args if argsInput is a string
63
+ // only strip those extra quotes in processValue if argsInput is a string
64
+ const inputIsString = typeof argsInput === 'string'
62
65
63
66
// aliases might have transitive relationships, normalize this.
64
67
const aliases = combineAliases ( Object . assign ( Object . create ( null ) , opts . alias ) )
@@ -243,7 +246,7 @@ export class YargsParser {
243
246
// nargs format = '--f=monkey washing cat'
244
247
i = eatNargs ( i , m [ 1 ] , args , m [ 2 ] )
245
248
} else {
246
- setArg ( m [ 1 ] , m [ 2 ] )
249
+ setArg ( m [ 1 ] , m [ 2 ] , true )
247
250
}
248
251
}
249
252
} else if ( arg . match ( negatedBoolean ) && configuration [ 'boolean-negation' ] ) {
@@ -516,15 +519,15 @@ export class YargsParser {
516
519
} else {
517
520
// value in --option=value is eaten as is
518
521
if ( ! isUndefined ( argAfterEqualSign ) ) {
519
- argsToSet . push ( processValue ( key , argAfterEqualSign ) )
522
+ argsToSet . push ( processValue ( key , argAfterEqualSign , true ) )
520
523
}
521
524
for ( let ii = i + 1 ; ii < args . length ; ii ++ ) {
522
525
if ( ( ! configuration [ 'greedy-arrays' ] && argsToSet . length > 0 ) ||
523
526
( nargsCount && typeof nargsCount === 'number' && argsToSet . length >= nargsCount ) ) break
524
527
next = args [ ii ]
525
528
if ( / ^ - / . test ( next ) && ! negative . test ( next ) && ! isUnknownOptionAsArg ( next ) ) break
526
529
i = ii
527
- argsToSet . push ( processValue ( key , next ) )
530
+ argsToSet . push ( processValue ( key , next , inputIsString ) )
528
531
}
529
532
}
530
533
@@ -540,15 +543,15 @@ export class YargsParser {
540
543
return i
541
544
}
542
545
543
- function setArg ( key : string , val : any ) : void {
546
+ function setArg ( key : string , val : any , shouldStripQuotes : boolean = inputIsString ) : void {
544
547
if ( / - / . test ( key ) && configuration [ 'camel-case-expansion' ] ) {
545
548
const alias = key . split ( '.' ) . map ( function ( prop ) {
546
549
return camelCase ( prop )
547
550
} ) . join ( '.' )
548
551
addNewAlias ( key , alias )
549
552
}
550
553
551
- const value = processValue ( key , val )
554
+ const value = processValue ( key , val , shouldStripQuotes )
552
555
const splitKey = key . split ( '.' )
553
556
setKey ( argv , splitKey , value )
554
557
@@ -605,13 +608,10 @@ export class YargsParser {
605
608
}
606
609
}
607
610
608
- function processValue ( key : string , val : any ) {
611
+ function processValue ( key : string , val : any , shouldStripQuotes : boolean ) {
609
612
// strings may be quoted, clean this up as we assign values.
610
- if ( typeof val === 'string' &&
611
- ( val [ 0 ] === "'" || val [ 0 ] === '"' ) &&
612
- val [ val . length - 1 ] === val [ 0 ]
613
- ) {
614
- val = val . substring ( 1 , val . length - 1 )
613
+ if ( shouldStripQuotes ) {
614
+ val = stripQuotes ( val )
615
615
}
616
616
617
617
// handle parsing boolean arguments --foo=true --bar false.
@@ -1116,3 +1116,13 @@ function sanitizeKey (key: string): string {
1116
1116
if ( key === '__proto__' ) return '___proto___'
1117
1117
return key
1118
1118
}
1119
+
1120
+ function stripQuotes ( val : string ) : string {
1121
+ return (
1122
+ typeof val === 'string' &&
1123
+ ( val [ 0 ] === "'" || val [ 0 ] === '"' ) &&
1124
+ val [ val . length - 1 ] === val [ 0 ]
1125
+ )
1126
+ ? val . substring ( 1 , val . length - 1 )
1127
+ : val
1128
+ }
0 commit comments