Bug 369349 - space in filename fix broke integration tests
+ fixing argument escaping so that it works with test-integration and jetty-osgi
This commit is contained in:
parent
b9590a575d
commit
b7e9d701d5
|
@ -27,13 +27,14 @@ public class CommandLineBuilder
|
|||
}
|
||||
|
||||
/**
|
||||
* Similar to {@link #addArg(String)} but does no quoting of the name parameter, and will quote the value parameter as needed.
|
||||
* Similar to {@link #addArg(String)} but concats both name + value with an "=" sign, quoting were needed, and excluding the "=" portion if the value is
|
||||
* undefined or empty.
|
||||
* <p>
|
||||
*
|
||||
* <pre>
|
||||
* addEqualsArg("-Dname", "value") = "-Dname=value"
|
||||
* addEqualsArg("-Djetty.home", "/opt/company inc/jetty (7)/") = "-Djetty.home=\"/opt/company inc/jetty (7)/\""
|
||||
* addEqualsArg("-Djenkins.workspace", "/opt/workspaces/jetty jdk7/") = "-Djenkins.workspace=\"/opt/workspaces/jetty jdk7/\""
|
||||
* addEqualsArg("-Djetty.home", "/opt/company inc/jetty (7)/") = "-Djetty.home=/opt/company\ inc/jetty\ (7)/"
|
||||
* addEqualsArg("-Djenkins.workspace", "/opt/workspaces/jetty jdk7/") = "-Djenkins.workspace=/opt/workspaces/jetty\ jdk7/"
|
||||
* addEqualsArg("-Dstress", null) = "-Dstress"
|
||||
* addEqualsArg("-Dstress", "") = "-Dstress"
|
||||
* </pre>
|
||||
|
@ -47,11 +48,11 @@ public class CommandLineBuilder
|
|||
{
|
||||
if (value != null && value.length() > 0)
|
||||
{
|
||||
args.add(name + "=" + quote(value));
|
||||
args.add(quote(name + "=" + value));
|
||||
}
|
||||
else
|
||||
{
|
||||
args.add(name);
|
||||
args.add(quote(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,27 +88,18 @@ public class CommandLineBuilder
|
|||
return arg;
|
||||
}
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append('"');
|
||||
// buf.append('"');
|
||||
boolean escaped = false;
|
||||
for (char c : arg.toCharArray())
|
||||
{
|
||||
if (c == '"')
|
||||
if (!escaped && ((c == '"') || (c == ' ')))
|
||||
{
|
||||
if (!escaped)
|
||||
{
|
||||
buf.append("\\\"");
|
||||
escaped = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (c == '\\')
|
||||
{
|
||||
escaped = true;
|
||||
buf.append("\\");
|
||||
}
|
||||
escaped = (c == '\\');
|
||||
buf.append(c);
|
||||
}
|
||||
buf.append('"');
|
||||
// buf.append('"');
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ public class CommandLineBuilderTest
|
|||
cmd.addEqualsArg("-Djava.io.tmpdir","/home/java/temp dir/");
|
||||
cmd.addArg("--version");
|
||||
|
||||
Assert.assertThat(cmd.toString(), is("java -Djava.io.tmpdir=\"/home/java/temp dir/\" --version"));
|
||||
Assert.assertThat(cmd.toString(), is("java -Djava.io.tmpdir=/home/java/temp\\ dir/ --version"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -25,13 +25,13 @@ public class CommandLineBuilderTest
|
|||
@Test
|
||||
public void testQuotingSpaceInPath()
|
||||
{
|
||||
assertQuoting("/opt/jetty 7/home","\"/opt/jetty 7/home\"");
|
||||
assertQuoting("/opt/jetty 7/home","/opt/jetty\\ 7/home");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuotingSpaceAndQuotesInPath()
|
||||
{
|
||||
assertQuoting("/opt/jetty 7 \"special\"/home","\"/opt/jetty 7 \\\"special\\\"/home\"");
|
||||
assertQuoting("/opt/jetty 7 \"special\"/home","/opt/jetty\\ 7\\ \\\"special\\\"/home");
|
||||
}
|
||||
|
||||
private void assertQuoting(String raw, String expected)
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -20,7 +20,7 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<slf4j-version>1.6.1</slf4j-version>
|
||||
<build-support-version>1.1</build-support-version>
|
||||
<jetty.test.helper>1.6</jetty.test.helper>
|
||||
<jetty.test.helper>1.6.1</jetty.test.helper>
|
||||
<jetty.test.policy>1.2</jetty.test.policy>
|
||||
</properties>
|
||||
<scm>
|
||||
|
|
Loading…
Reference in New Issue