diff mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BaseCommandTest.java @ 229:9e60b6d1e5fd build-snapshot-124

Escape quotes in command line parameters * * * Escape quotes in command line parameters
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Thu, 14 Apr 2011 14:39:31 +0400
parents
children 8c10f5cec37d
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BaseCommandTest.java	Thu Apr 14 14:39:31 2011 +0400
@@ -0,0 +1,38 @@
+package jetbrains.buildServer.buildTriggers.vcs.mercurial.command;
+
+import com.intellij.execution.configurations.GeneralCommandLine;
+import com.intellij.openapi.util.SystemInfo;
+import jetbrains.buildServer.buildTriggers.vcs.mercurial.Constants;
+import jetbrains.buildServer.buildTriggers.vcs.mercurial.Util;
+import jetbrains.buildServer.vcs.impl.VcsRootImpl;
+import junit.framework.TestCase;
+import org.testng.annotations.Test;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * @author dmitry.neverov
+ */
+@Test
+public class BaseCommandTest extends TestCase {
+
+  public void should_quote_command_line_arguments() throws IOException {
+    VcsRootImpl root = new VcsRootImpl(1, "rootForTest");
+    root.addProperty(Constants.REPOSITORY_PROP, "http://some.org/repo.hg");
+    root.addProperty(Constants.HG_COMMAND_PATH_PROP, Util.getHgPath());
+    File workingDir = new File("some dir");
+    Settings settings = new Settings(root);
+
+    BaseCommand command = new BaseCommand(settings, workingDir);
+    GeneralCommandLine cl = command.createCommandLine();
+    cl.addParameter("param with spaces");
+    cl.addParameter("param with quote \" rm -rf /");
+    if (SystemInfo.isWindows) {
+      assertTrue(cl.getCommandLineString().endsWith(" \"param with spaces\" \"param with quote \\\" rm -rf /\""));
+    } else {
+      assertTrue(cl.getCommandLineString().endsWith(" param with spaces param with quote \" rm -rf /"));
+    }
+  }
+
+}