You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kh...@apache.org on 2018/07/26 16:48:12 UTC

[maven-shared-utils] branch MSHARED-416 updated (05bb4bd -> 6a57059)

This is an automated email from the ASF dual-hosted git repository.

khmarbaise pushed a change to branch MSHARED-416
in repository https://gitbox.apache.org/repos/asf/maven-shared-utils.git.


 discard 05bb4bd  MSHARED-416 Added test for uneven number of double quotations and refactored finals
 discard be1635f  MSHARED-416: Added double quotes as wrapper around arguments for shell
     new 6a57059  [MSHARED-416] Odd number of quotes in command-line fails

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (05bb4bd)
            \
             N -- N -- N   refs/heads/MSHARED-416 (6a57059)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../maven/shared/utils/cli/CommandLineUtilsTest.java    | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)


[maven-shared-utils] 01/01: [MSHARED-416] Odd number of quotes in command-line fails

Posted by kh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

khmarbaise pushed a commit to branch MSHARED-416
in repository https://gitbox.apache.org/repos/asf/maven-shared-utils.git

commit 6a570592964b67168618ae5baca4cd822dba9398
Author: Kathryn <ka...@anaplan.com>
AuthorDate: Thu Jul 26 15:45:12 2018 +0100

    [MSHARED-416] Odd number of quotes in command-line fails
---
 .../org/apache/maven/shared/utils/StringUtils.java |  8 +++---
 .../maven/shared/utils/cli/shell/BourneShell.java  |  8 ++++--
 .../shared/utils/cli/CommandLineUtilsTest.java     | 32 ++++++++++++++++++++--
 .../shared/utils/cli/shell/BourneShellTest.java    | 14 +++++-----
 4 files changed, 46 insertions(+), 16 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/utils/StringUtils.java b/src/main/java/org/apache/maven/shared/utils/StringUtils.java
index 58bf8be..6b9a55a 100644
--- a/src/main/java/org/apache/maven/shared/utils/StringUtils.java
+++ b/src/main/java/org/apache/maven/shared/utils/StringUtils.java
@@ -2290,9 +2290,9 @@ public class StringUtils
     /**
      * @param source The source.
      * @param quoteChar The quote character.
-     * @param escapedChars The escaped characters.
+     * @param escapedChars set of characters to escape.
      * @param quotingTriggers The quoting trigger.
-     * @param escapeChar The escape character.
+     * @param escapeChar prefix for escaping a character.
      * @param force true/false.
      * @return the String quoted and escaped
      */
@@ -2343,8 +2343,8 @@ public class StringUtils
 
     /**
      * @param source The source.
-     * @param escapedChars escape characters.
-     * @param escapeChar escape character.
+     * @param escapedChars set of characters to escape.
+     * @param escapeChar prefix for escaping a character.
      * @return the String escaped
      */
     public static String escape( @Nullable String source, @Nonnull final char[] escapedChars, char escapeChar )
diff --git a/src/main/java/org/apache/maven/shared/utils/cli/shell/BourneShell.java b/src/main/java/org/apache/maven/shared/utils/cli/shell/BourneShell.java
index 8116707..1793cbb 100644
--- a/src/main/java/org/apache/maven/shared/utils/cli/shell/BourneShell.java
+++ b/src/main/java/org/apache/maven/shared/utils/cli/shell/BourneShell.java
@@ -31,17 +31,19 @@ import org.apache.maven.shared.utils.StringUtils;
 public class BourneShell
     extends Shell
 {
+    private static final char DOUBLE_QUOTATION = '"';
+
     private static final char[] BASH_QUOTING_TRIGGER_CHARS =
         { ' ', '$', ';', '&', '|', '<', '>', '*', '?', '(', ')', '[', ']', '{', '}', '`' };
 
     /**
-     * Create instance of BournShell.
+     * Create instance of BourneShell.
      */
     public BourneShell()
     {
         setShellCommand( "/bin/sh" );
-        setArgumentQuoteDelimiter( '\'' );
-        setExecutableQuoteDelimiter( '\"' );
+        setArgumentQuoteDelimiter( DOUBLE_QUOTATION );
+        setExecutableQuoteDelimiter( DOUBLE_QUOTATION );
         setSingleQuotedArgumentEscaped( true );
         setSingleQuotedExecutableEscaped( false );
         setQuotedExecutableEnabled( true );
diff --git a/src/test/java/org/apache/maven/shared/utils/cli/CommandLineUtilsTest.java b/src/test/java/org/apache/maven/shared/utils/cli/CommandLineUtilsTest.java
index 0f8b799..4ed35ed 100644
--- a/src/test/java/org/apache/maven/shared/utils/cli/CommandLineUtilsTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/cli/CommandLineUtilsTest.java
@@ -19,22 +19,27 @@ package org.apache.maven.shared.utils.cli;
  * under the License.
  */
 
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Properties;
+
 import org.apache.maven.shared.utils.Os;
 
-import junit.framework.TestCase;
+import org.junit.Test;
 
 public class CommandLineUtilsTest
-    extends TestCase
 {
 
     /**
      * Tests that case-insensitive environment variables are normalized to upper case.
      */
+    @Test
     public void testGetSystemEnvVarsCaseInsensitive()
     {
         Properties vars = CommandLineUtils.getSystemEnvVars( false );
@@ -45,6 +50,7 @@ public class CommandLineUtilsTest
         }
     }
 
+    @Test
     public void testEnsureCaseSensitivity()
         throws Exception
     {
@@ -57,6 +63,7 @@ public class CommandLineUtilsTest
     /**
      * Tests that environment variables on Windows are normalized to upper case. Does nothing on Unix platforms.
      */
+    @Test
     public void testGetSystemEnvVarsWindows()
         throws Exception
     {
@@ -75,6 +82,7 @@ public class CommandLineUtilsTest
     /**
      * Tests the splitting of a command line into distinct arguments.
      */
+    @Test
     public void testTranslateCommandline()
         throws Exception
     {
@@ -91,6 +99,26 @@ public class CommandLineUtilsTest
         assertCmdLineArgs( new String[] { "foo", " ' ", "bar" }, "foo \" ' \" bar" );
     }
 
+    @Test
+    public void givenASingleQuoteMarkInArgument_whenExecutingCode_thenExitCode0Returned() throws Exception {
+        final Process p = exec("echo \"let's go\"");
+
+        assertEquals(0, p.exitValue());
+    }
+
+    @Test
+    public void givenADoubleQuoteMarkInArgument_whenExecutingCode_thenExitCode0Returned() throws Exception {
+        final Process p = exec("echo \"let\"s go\"");
+
+        assertEquals(0, p.exitValue());
+    }
+
+    private Process exec(String cmd) throws CommandLineException, InterruptedException {
+        Process p = new Commandline(cmd).execute();
+        Thread.sleep(1000);
+        return p;
+    }
+
     private void assertCmdLineArgs( String[] expected, String cmdLine )
         throws Exception
     {
diff --git a/src/test/java/org/apache/maven/shared/utils/cli/shell/BourneShellTest.java b/src/test/java/org/apache/maven/shared/utils/cli/shell/BourneShellTest.java
index cfca54b..c83287c 100644
--- a/src/test/java/org/apache/maven/shared/utils/cli/shell/BourneShellTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/cli/shell/BourneShellTest.java
@@ -78,7 +78,7 @@ public class BourneShellTest
         sh.setWorkingDirectory( "/usr/bin" );
         sh.setExecutable( "chmod" );
 
-        String[] args = { "\'some arg with spaces\'" };
+        final String[] args = { "\"some arg with spaces\"" };
 
         List<String> shellCommandLine = sh.getShellCommandLine( args );
 
@@ -100,10 +100,10 @@ public class BourneShellTest
 
         String cli = StringUtils.join( shellCommandLine.iterator(), " " );
         System.out.println( cli );
-        assertTrue( cli.endsWith( "\'" + args[0] + "\'" ) );
+        assertTrue( cli.endsWith( "\"" + args[0] + "\"" ) );
     }
 
-    public void testArgumentsWithsemicolon()
+    public void testArgumentsWithSemicolon()
     {
 
         System.out.println( "---- semi colon tests ----" );
@@ -119,7 +119,7 @@ public class BourneShellTest
 
         String cli = StringUtils.join( shellCommandLine.iterator(), " " );
         System.out.println( cli );
-        assertTrue( cli.endsWith( "\'" + args[0] + "\'" ) );
+        assertTrue( cli.endsWith( "\"" + args[0] + "\"" ) );
 
         Commandline commandline = new Commandline( newShell() );
         commandline.setExecutable( "chmod" );
@@ -132,7 +132,7 @@ public class BourneShellTest
 
         assertEquals( "/bin/sh", lines.get( 0 ) );
         assertEquals( "-c", lines.get( 1 ) );
-        assertEquals( "chmod --password ';password'", lines.get( 2 ) );
+        assertEquals( "chmod --password \";password\"", lines.get( 2 ) );
 
         commandline = new Commandline( newShell() );
         commandline.setExecutable( "chmod" );
@@ -144,7 +144,7 @@ public class BourneShellTest
 
         assertEquals( "/bin/sh", lines.get( 0) );
         assertEquals( "-c", lines.get( 1 ) );
-        assertEquals( "chmod --password ';password'", lines.get( 2 ) );
+        assertEquals( "chmod --password \";password\"", lines.get( 2 ) );
 
         commandline = new Commandline( new CmdShell() );
         commandline.getShell().setQuotedArgumentsEnabled( true );
@@ -192,7 +192,7 @@ public class BourneShellTest
 
         assertEquals( "/bin/sh", lines.get( 0 ) );
         assertEquals( "-c", lines.get( 1 ) );
-        assertEquals( "chmod ' ' '|' '&&' '||' ';' ';;' '&' '()' '<' '<<' '>' '>>' '*' '?' '[' ']' '{' '}' '`'",
+        assertEquals( "chmod \" \" \"|\" \"&&\" \"||\" \";\" \";;\" \"&\" \"()\" \"<\" \"<<\" \">\" \">>\" \"*\" \"?\" \"[\" \"]\" \"{\" \"}\" \"`\"",
                       lines.get( 2 ) );
     }