]> source.dussan.org Git - jgit.git/commitdiff
Remove quoting of command over SSH 35/2435/1
authorShawn O. Pearce <spearce@spearce.org>
Sun, 6 Feb 2011 22:04:39 +0000 (14:04 -0800)
committerShawn O. Pearce <spearce@spearce.org>
Sun, 6 Feb 2011 22:04:39 +0000 (14:04 -0800)
If the command contains spaces, it needs to be evaluated by the remote
shell.  Quoting the command breaks this, making it impossible to run a
remote command that needs additional options.

Bug: 336301
Change-Id: Ib5d88f0b2151df2d1d2b4e08d51ee979f6da67b5
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitSsh.java

index e6609e6719298776824549d7219e1a3d9dd21cce..7ad5fc71c12f61fbea30476c4e42d8c2b060d22d 100644 (file)
@@ -115,44 +115,15 @@ public class TransportGitSsh extends SshTransport implements PackTransport {
                return new JschConnection();
        }
 
-       private static void sqMinimal(final StringBuilder cmd, final String val) {
-               if (val.matches("^[a-zA-Z0-9._/-]*$")) {
-                       // If the string matches only generally safe characters
-                       // that the shell is not going to evaluate specially we
-                       // should leave the string unquoted. Not all systems
-                       // actually run a shell and over-quoting confuses them
-                       // when it comes to the command name.
-                       //
-                       cmd.append(val);
-               } else {
-                       sq(cmd, val);
-               }
-       }
-
-       private static void sqAlways(final StringBuilder cmd, final String val) {
-               sq(cmd, val);
-       }
-
-       private static void sq(final StringBuilder cmd, final String val) {
-               if (val.length() > 0)
-                       cmd.append(QuotedString.BOURNE.quote(val));
-       }
-
        String commandFor(final String exe) {
                String path = uri.getPath();
                if (uri.getScheme() != null && uri.getPath().startsWith("/~"))
                        path = (uri.getPath().substring(1));
 
                final StringBuilder cmd = new StringBuilder();
-               final int gitspace = exe.indexOf("git ");
-               if (gitspace >= 0) {
-                       sqMinimal(cmd, exe.substring(0, gitspace + 3));
-                       cmd.append(' ');
-                       sqMinimal(cmd, exe.substring(gitspace + 4));
-               } else
-                       sqMinimal(cmd, exe);
+               cmd.append(exe);
                cmd.append(' ');
-               sqAlways(cmd, path);
+               cmd.append(QuotedString.BOURNE.quote(path));
                return cmd.toString();
        }
 
@@ -178,7 +149,7 @@ public class TransportGitSsh extends SshTransport implements PackTransport {
 
                final StringBuilder pfx = new StringBuilder();
                pfx.append("fatal: ");
-               sqAlways(pfx, path);
+               pfx.append(QuotedString.BOURNE.quote(path));
                pfx.append(": ");
                if (why.startsWith(pfx.toString()))
                        why = why.substring(pfx.length());