view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BaseCommandTest.java @ 228:26febf4e58a2 remote-run/dmitry.neverov/escaping

Escape quotes in command line parameters
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Thu, 14 Apr 2011 15:06:35 +0400
parents 061486453bd9
children
line wrap: on
line source
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 /"));
    }
  }

}