TW-51968 fix single quote escaping in passwords
authorDmitry Neverov <dmitry.neverov@gmail.com>
Wed, 25 Oct 2017 07:04:30 +0000 (09:04 +0200)
committerDmitry Neverov <dmitry.neverov@gmail.com>
Wed, 25 Oct 2017 07:04:30 +0000 (09:04 +0200)
git-agent/src/jetbrains/buildServer/buildTriggers/vcs/git/agent/command/impl/EscapeEchoArgumentUnix.java
git-tests/src/jetbrains/buildServer/buildTriggers/vcs/git/tests/EchoArgumentEscapingTest.java
git-tests/src/jetbrains/buildServer/buildTriggers/vcs/git/tests/HttpAuthTest.java

index 985269459e55eb0cd2dde7b46778886fb3c14a61..7fd7beb5e27391f43c4e25952471e6b713b6e750 100644 (file)
@@ -31,7 +31,9 @@ public class EscapeEchoArgumentUnix implements EscapeEchoArgument {
       char c = s.charAt(i);
       switch (c) {
         case '\'':
-          sb.append("\\'");
+          //we cannot escape ' inside 'string', we have to close 'string',
+          //add escaped ' and open next 'string'
+          sb.append("'\\''");
           break;
         case '\\':
           sb.append("\\\\");
index 1041dca042155966c75f14d3660ecd49912738fe..89f61fd11ff3eb7708e4d211db6be16396bc0ab9 100644 (file)
@@ -41,6 +41,7 @@ public class EchoArgumentEscapingTest {
     assertEquals("'ab'", escaper.escape("ab"));
     assertEquals("'a\\\\\"b'", escaper.escape("a\\\"b"));
     assertEquals("''", escaper.escape(null));
+    assertEquals("'a'\\''b'", escaper.escape("a'b"));//TW-51968
   }
 
 }
index bb40bc1c3a8cf476305f08441a047736c79848ee..71c139c22a20fbb9af80fb08fdec7bb08c81a743 100644 (file)
@@ -125,7 +125,36 @@ public class HttpAuthTest extends BaseRemoteRepositoryTest {
   }
 
 
-  private class Checkout extends Thread {
+  @TestFor(issues = "TW-51968")
+  public void quote_in_password(@NotNull GitExec git) throws Exception {
+    File repo = copyRepository(myTempFiles, dataFile("repo_for_fetch.1"), "repo.git");
+
+    final String user = "user";
+    final String password = "pass'word";
+    myServer = new GitHttpServer(git.getPath(), repo);
+    myServer.setCredentials(user, password);
+    myServer.start();
+
+    VcsRootImpl root = vcsRoot()
+      .withFetchUrl(myServer.getRepoUrl())
+      .withAuthMethod(AuthenticationMethod.PASSWORD)
+      .withUsername(user)
+      .withPassword(password)
+      .withBranch("master")
+      .build();
+
+    File buildDir = myTempFiles.createTempDir();
+    AgentRunningBuild build = runningBuild()
+      .sharedEnvVariable(Constants.TEAMCITY_AGENT_GIT_PATH, git.getPath())
+      .build();
+
+    Checkout checkout = new Checkout(root, "add81050184d3c818560bdd8839f50024c188586", buildDir, build);
+    checkout.run(TimeUnit.SECONDS.toMillis(10));
+    assertTrue(checkout.success());
+  }
+
+
+    private class Checkout extends Thread {
     private final VcsRootImpl myRoot;
     private final String myRevision;
     private final File myBuildDir;