@@ -45,39 +45,41 @@ const FS = ({
4545 }
4646} ;
4747
48- const parseArgs = ( command ) => {
48+ const parseArgs = ( cmd ) => {
4949 const args = [ ] ;
5050 let nextDelimiter = 0 ;
5151 let prevDelimiter = 0 ;
52- while ( ( nextDelimiter = command . indexOf ( ' ' , prevDelimiter ) ) >= 0 ) {
53- let arg = command . substring ( prevDelimiter , nextDelimiter ) ;
54- let quoteIndex = arg . indexOf ( '\'' ) ;
55- let doubleQuoteIndex = arg . indexOf ( '"' ) ;
52+ // eslint-disable-next-line no-cond-assign
53+ while ( ( nextDelimiter = cmd . indexOf ( ' ' , prevDelimiter ) ) >= 0 ) {
54+ let arg = cmd . substring ( prevDelimiter , nextDelimiter ) ;
55+ let quoteIdx = arg . indexOf ( '\'' ) ;
56+ let dblQuoteIdx = arg . indexOf ( '"' ) ;
5657
57- if ( quoteIndex === 0 || doubleQuoteIndex === 0 ) {
58+ if ( quoteIdx === 0 || dblQuoteIdx === 0 ) {
5859 /* The argument has a quote at the start i.e, 'id=0,streams=0 id=1,streams=1' */
5960 const delimiter = arg [ 0 ] ;
60- const endDelimiter = command . indexOf ( delimiter , prevDelimiter + 1 ) ;
61+ const endDelimiter = cmd . indexOf ( delimiter , prevDelimiter + 1 ) ;
6162
6263 if ( endDelimiter < 0 ) {
6364 throw new Error ( `Bad command escape sequence ${ delimiter } near ${ nextDelimiter } ` ) ;
6465 }
6566
66- arg = command . substring ( prevDelimiter + 1 , endDelimiter ) ;
67+ arg = cmd . substring ( prevDelimiter + 1 , endDelimiter ) ;
6768 prevDelimiter = endDelimiter + 2 ;
6869 args . push ( arg ) ;
69- } else if ( quoteIndex > 0 || doubleQuoteIndex > 0 ) {
70+ } else if ( quoteIdx > 0 || dblQuoteIdx > 0 ) {
7071 /* The argument has a quote in it, it must be ended correctly i,e. title='test' */
71- if ( quoteIndex === - 1 ) quoteIndex = Infinity ;
72- if ( doubleQuoteIndex === - 1 ) doubleQuoteIndex = Infinity ;
73- const delimiter = ( quoteIndex < doubleQuoteIndex ) ? '\'' : '"' ;
74- const endDelimiter = command . indexOf ( delimiter , prevDelimiter + Math . min ( quoteIndex , doubleQuoteIndex ) + 1 ) ;
72+ if ( quoteIdx === - 1 ) quoteIdx = Infinity ;
73+ if ( dblQuoteIdx === - 1 ) dblQuoteIdx = Infinity ;
74+ const delimiter = ( quoteIdx < dblQuoteIdx ) ? '\'' : '"' ;
75+ const quoteOffset = Math . min ( quoteIdx , dblQuoteIdx ) ;
76+ const endDelimiter = cmd . indexOf ( delimiter , prevDelimiter + quoteOffset + 1 ) ;
7577
7678 if ( endDelimiter < 0 ) {
7779 throw new Error ( `Bad command escape sequence ${ delimiter } near ${ nextDelimiter } ` ) ;
7880 }
7981
80- arg = command . substring ( prevDelimiter , endDelimiter + 1 ) ;
82+ arg = cmd . substring ( prevDelimiter , endDelimiter + 1 ) ;
8183 prevDelimiter = endDelimiter + 2 ;
8284 args . push ( arg ) ;
8385 } else if ( arg !== '' ) {
@@ -88,8 +90,8 @@ const parseArgs = (command) => {
8890 }
8991 }
9092
91- if ( prevDelimiter !== command . length ) {
92- args . push ( command . substring ( prevDelimiter ) ) ;
93+ if ( prevDelimiter !== cmd . length ) {
94+ args . push ( cmd . substring ( prevDelimiter ) ) ;
9395 }
9496
9597 return args ;
0 commit comments