From 0180946bc885436be2d3c205c7444bcdd57d85cd Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 6 Feb 2011 14:04:39 -0800 Subject: [PATCH] Remove quoting of command over SSH 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 --- .../jgit/transport/TransportGitSsh.java | 35 ++----------------- 1 file changed, 3 insertions(+), 32 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitSsh.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitSsh.java index e6609e6719..7ad5fc71c1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitSsh.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitSsh.java @@ -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()); -- 2.39.5