提交 e41b55cd 编写于 作者: M mindless

[FIXED HUDSON-7657] While testing from command prompt requires escaping of ^&<>|

with a ^ character, this is apparently not needed when cmd.exe /C is invoked from
Hudson.. commented that part of toWindowsCommand() and updated javadoc/unit test.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@36903 71c3de6d-444a-0410-be80-ed276b4c234a
上级 83c040c4
......@@ -286,15 +286,18 @@ public class ArgumentListBuilder implements Serializable {
* This is done as follows:
* Wrap arguments in double quotes if they contain any of:
* space *?,;^&<>|" or % followed by a letter.
* <br/> These characters are also prepended with a ^ character: ^&<>|
* <br/> When testing from command prompt, these characters also need to be
* prepended with a ^ character: ^&<>| -- however, invoking cmd.exe from
* Hudson does not seem to require this extra escaping so it is not added by
* this method.
* <br/> A " is prepended with another " character. Note: Windows has issues
* escaping some combinations of quotes and spaces. Quotes should be avoided.
* <br/> A % followed by a letter has that letter wrapped in double quotes,
* to avoid possible variable expansion. ie, %foo% becomes "%"f"oo%".
* The second % does not need special handling because it is not followed
* by a letter. <br/>
* Example: "-Dfoo=*abc?def;ghi^^jkl^&mno^<pqr^>stu^|vwx""yz%"e"nd"
* @return
* Example: "-Dfoo=*abc?def;ghi^jkl&mno<pqr>stu|vwx""yz%"e"nd"
* @return new ArgumentListBuilder that runs given command through cmd.exe /C
*/
public ArgumentListBuilder toWindowsCommand() {
StringBuilder quotedArgs = new StringBuilder();
......@@ -308,7 +311,7 @@ public class ArgumentListBuilder implements Serializable {
}
else if (c == '^' || c == '&' || c == '<' || c == '>' || c == '|') {
if (!quoted) quoted = startQuoting(quotedArgs, arg, i);
quotedArgs.append('^');
// quotedArgs.append('^'); See note in javadoc above
}
else if (c == '"') {
if (!quoted) quoted = startQuoting(quotedArgs, arg, i);
......
......@@ -113,16 +113,16 @@ public class ArgumentListBuilderTest extends Assert {
public void testToWindowsCommand() {
ArgumentListBuilder builder = new ArgumentListBuilder(
"ant.bat", "-Dfoo1=abc", // nothing special, no quotes
"-Dfoo2=foo bar", "-Dfoo3=/u*r", "-Dfoo4=/us?", // add quotes, no other escaping
"-Dfoo2=foo bar", "-Dfoo3=/u*r", "-Dfoo4=/us?", // add quotes
"-Dfoo10=bar,baz",
"-Dfoo5=foo;bar^baz", "-Dfoo6=<xml>&here;</xml>", // add quotes and ^ escaping
"-Dfoo7=foo|bar\"baz", // add quotes, ^| for | and "" for "
"-Dfoo5=foo;bar^baz", "-Dfoo6=<xml>&here;</xml>", // add quotes
"-Dfoo7=foo|bar\"baz", // add quotes and "" for "
"-Dfoo8=% %QED% %comspec% %-%(%.%", // add quotes, and extra quotes for %Q and %c
"-Dfoo9=%'''%%@%"); // no quotes as none of the % are followed by a letter
assertArrayEquals(new String[] { "cmd.exe", "/C",
"\"ant.bat -Dfoo1=abc \"-Dfoo2=foo bar\""
+ " \"-Dfoo3=/u*r\" \"-Dfoo4=/us?\" \"-Dfoo10=bar,baz\" \"-Dfoo5=foo;bar^^baz\""
+ " \"-Dfoo6=^<xml^>^&here;^</xml^>\" \"-Dfoo7=foo^|bar\"\"baz\""
+ " \"-Dfoo3=/u*r\" \"-Dfoo4=/us?\" \"-Dfoo10=bar,baz\" \"-Dfoo5=foo;bar^baz\""
+ " \"-Dfoo6=<xml>&here;</xml>\" \"-Dfoo7=foo|bar\"\"baz\""
+ " \"-Dfoo8=% %\"Q\"ED% %\"c\"omspec% %-%(%.%\""
+ " -Dfoo9=%'''%%@% && exit %%ERRORLEVEL%%\"" },
builder.toWindowsCommand().toCommandArray());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册