aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Becker2013-06-10 12:01:07 (EDT)
committerJoakim Erdfelt2013-06-17 12:19:03 (EDT)
commita05efd43d4ffe005f66144656e62496fce1016c2 (patch)
tree7f32373b740049fb85abc75e94c0a504ef548f35
parent00744e42fcef3d79fa495eb2cd04d13a4a9eeeea (diff)
downloadorg.eclipse.jetty.project-a05efd43d4ffe005f66144656e62496fce1016c2.zip
org.eclipse.jetty.project-a05efd43d4ffe005f66144656e62496fce1016c2.tar.gz
org.eclipse.jetty.project-a05efd43d4ffe005f66144656e62496fce1016c2.tar.bz2
408904 Enhance CommandlineBuilder to not escape strings inside single quotes
-rw-r--r--jetty-start/src/main/java/org/eclipse/jetty/start/CommandLineBuilder.java11
-rw-r--r--jetty-start/src/test/java/org/eclipse/jetty/start/CommandLineBuilderTest.java16
2 files changed, 20 insertions, 7 deletions
diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/CommandLineBuilder.java b/jetty-start/src/main/java/org/eclipse/jetty/start/CommandLineBuilder.java
index 16242ff..d50a4b7 100644
--- a/jetty-start/src/main/java/org/eclipse/jetty/start/CommandLineBuilder.java
+++ b/jetty-start/src/main/java/org/eclipse/jetty/start/CommandLineBuilder.java
@@ -95,7 +95,8 @@ public class CommandLineBuilder
}
/**
- * Perform an optional quoting of the argument, being intelligent with spaces and quotes as needed.
+ * Perform an optional quoting of the argument, being intelligent with spaces and quotes as needed. If a
+ * subString is set in quotes it won't the subString won't be escaped.
*
* @param arg
* @return
@@ -110,12 +111,18 @@ public class CommandLineBuilder
StringBuilder buf = new StringBuilder();
// buf.append('"');
boolean escaped = false;
+ boolean quoted = false;
for (char c : arg.toCharArray())
{
- if (!escaped && ((c == '"') || (c == ' ')))
+ if (!quoted && !escaped && ((c == '"') || (c == ' ')))
{
buf.append("\\");
}
+ // don't quote text in single quotes
+ if (!escaped && c == '\'')
+ {
+ quoted = !quoted;
+ }
escaped = (c == '\\');
buf.append(c);
}
diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/CommandLineBuilderTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/CommandLineBuilderTest.java
index 967e369..562d408 100644
--- a/jetty-start/src/test/java/org/eclipse/jetty/start/CommandLineBuilderTest.java
+++ b/jetty-start/src/test/java/org/eclipse/jetty/start/CommandLineBuilderTest.java
@@ -18,12 +18,12 @@
package org.eclipse.jetty.start;
-import static org.hamcrest.Matchers.is;
-
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
public class CommandLineBuilderTest
{
private CommandLineBuilder cmd = new CommandLineBuilder("java");
@@ -38,7 +38,7 @@ public class CommandLineBuilderTest
@Test
public void testSimpleCommandline()
{
- Assert.assertThat(cmd.toString(),is("java -Djava.io.tmpdir=/home/java/temp\\ dir/ --version"));
+ assertThat(cmd.toString(), is("java -Djava.io.tmpdir=/home/java/temp\\ dir/ --version"));
}
@Test
@@ -65,9 +65,15 @@ public class CommandLineBuilderTest
System.out.println(cmd.toString());
}
+ @Test
+ public void testQuoteQuotationMarks()
+ {
+ assertQuoting("-XX:OnOutOfMemoryError='kill -9 %p'","-XX:OnOutOfMemoryError='kill -9 %p'");
+ }
+
private void assertQuoting(String raw, String expected)
{
String actual = CommandLineBuilder.quote(raw);
- Assert.assertThat("Quoted version of [" + raw + "]",actual,is(expected));
+ assertThat("Quoted version of [" + raw + "]", actual, is(expected));
}
}