@@ -216,13 +216,14 @@ private static String[] getTokensFromCommand(String command) {
216216 private static final int VERIFICATION_LEGACY = 3 ;
217217 // See Command shell overview for documentation of special characters.
218218 // https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-xp/bb490954(v=technet.10)
219- private static final char ESCAPE_VERIFICATION [] [] = {
219+ private static final String ESCAPE_VERIFICATION [] = {
220220 // We guarantee the only command file execution for implicit [cmd.exe] run.
221221 // http://technet.microsoft.com/en-us/library/bb490954.aspx
222- {' ' , '\t' , '\"' , '<' , '>' , '&' , '|' , '^' },
223- {' ' , '\t' , '\"' , '<' , '>' },
224- {' ' , '\t' , '\"' , '<' , '>' },
225- {' ' , '\t' }
222+ // All space characters require quoting are checked in needsEscaping().
223+ "\" <>&|^" ,
224+ "\" <>" ,
225+ "\" <>" ,
226+ ""
226227 };
227228
228229 private static String createCommandLine (int verificationType ,
@@ -337,9 +338,14 @@ private static boolean needsEscaping(int verificationType, String arg) {
337338 }
338339
339340 if (!argIsQuoted ) {
340- char testEscape [] = ESCAPE_VERIFICATION [verificationType ];
341- for (int i = 0 ; i < testEscape .length ; ++i ) {
342- if (arg .indexOf (testEscape [i ]) >= 0 ) {
341+ for (int i = 0 ; i < arg .length (); i ++) {
342+ char ch = arg .charAt (i );
343+ if (Character .isLetterOrDigit (ch ))
344+ continue ; // skip over common characters
345+ // All space chars require quotes and other mode specific characters
346+ if (Character .isSpaceChar (ch ) ||
347+ Character .isWhitespace (ch ) ||
348+ ESCAPE_VERIFICATION [verificationType ].indexOf (ch ) >= 0 ) {
343349 return true ;
344350 }
345351 }
0 commit comments