comparison 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
comparison
equal deleted inserted replaced
227:061486453bd9 228:26febf4e58a2
8 import junit.framework.TestCase; 8 import junit.framework.TestCase;
9 import org.testng.annotations.Test; 9 import org.testng.annotations.Test;
10 10
11 import java.io.File; 11 import java.io.File;
12 import java.io.IOException; 12 import java.io.IOException;
13 import java.util.List;
14 13
15 /** 14 /**
16 * @author dmitry.neverov 15 * @author dmitry.neverov
17 */ 16 */
18 @Test 17 @Test
27 26
28 BaseCommand command = new BaseCommand(settings, workingDir); 27 BaseCommand command = new BaseCommand(settings, workingDir);
29 GeneralCommandLine cl = command.createCommandLine(); 28 GeneralCommandLine cl = command.createCommandLine();
30 cl.addParameter("param with spaces"); 29 cl.addParameter("param with spaces");
31 cl.addParameter("param with quote \" rm -rf /"); 30 cl.addParameter("param with quote \" rm -rf /");
32 List<String> params = cl.getParametersList().getList();
33 if (SystemInfo.isWindows) { 31 if (SystemInfo.isWindows) {
34 assertEquals("\"param with spaces\"", params.get(0)); 32 assertTrue(cl.getCommandLineString().endsWith(" \"param with spaces\" \"param with quote \\\" rm -rf /\""));
35 assertEquals("\"param with quote \\\" rm -rf /\"", params.get(1));
36 } else { 33 } else {
37 assertEquals("param with spaces", params.get(0)); 34 assertTrue(cl.getCommandLineString().endsWith(" param with spaces param with quote \" rm -rf /"));
38 assertEquals("param with quote \" rm -rf /", params.get(1));
39 } 35 }
40 } 36 }
41 37
42 } 38 }