Skip to content

Commit

Permalink
o Fixed argument quoting to recognize more special characters
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/maven/shared/trunk@931543 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
bentmann committed Apr 7, 2010
1 parent a373043 commit 6e24484
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ public String toString()
public static String quoteArgument( String argument )
throws CommandLineException
{
if ( argument.indexOf( "\"" ) > -1 )
if ( argument.indexOf( '\"' ) > -1 )
{
if ( argument.indexOf( "\'" ) > -1 )
if ( argument.indexOf( '\'' ) > -1 )
{
throw new CommandLineException( "Can't handle single and double quotes in same argument" );
}
Expand All @@ -523,7 +523,7 @@ public static String quoteArgument( String argument )
return '\'' + argument + '\'';
}
}
else if ( argument.indexOf( "\'" ) > -1 || argument.indexOf( " " ) > -1 )
else if ( containsAny( argument, "'<>&|*? " ) )
{
return '\"' + argument + '\"';
}
Expand All @@ -533,6 +533,18 @@ else if ( argument.indexOf( "\'" ) > -1 || argument.indexOf( " " ) > -1 )
}
}

private static boolean containsAny( String argument, String chars )
{
for ( int i = chars.length() - 1; i >= 0; i-- )
{
if ( argument.indexOf( chars.charAt( i ) ) >= 0 )
{
return true;
}
}
return false;
}

public static String toString( String[] line )
{
// empty path return empty string
Expand Down

0 comments on commit 6e24484

Please sign in to comment.