Browse Source

Preserve backslashes within double quotes in CLIGitCommand::split()

Change-Id: Ia6a56512baa6a0f27e2eef1b19ebb60291ba377f
Signed-off-by: Rüdiger Herrmann <ruediger.herrmann@gmx.de>
stable-4.6
Rüdiger Herrmann 9 years ago committed by David Pursehouse
parent
commit
a5eccf4a4d
  1. 2
      org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java
  2. 2
      org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CLIGitCommandTest.java

2
org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java

@ -218,7 +218,7 @@ public class CLIGitCommand extends Main {
inquote = !inquote; inquote = !inquote;
continue; continue;
case '\\': case '\\':
if (inquote || ip == commandLine.length()) if (inDblQuote || inquote || ip == commandLine.length())
r.append(b); // literal within a quote r.append(b); // literal within a quote
else else
r.append(commandLine.charAt(ip++)); r.append(commandLine.charAt(ip++));

2
org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CLIGitCommandTest.java

@ -51,9 +51,11 @@ public class CLIGitCommandTest {
@Test @Test
public void testSplit() throws Exception { public void testSplit() throws Exception {
assertArrayEquals(new String[0], split(""));
assertArrayEquals(new String[] { "a" }, split("a")); assertArrayEquals(new String[] { "a" }, split("a"));
assertArrayEquals(new String[] { "a", "b" }, split("a b")); assertArrayEquals(new String[] { "a", "b" }, split("a b"));
assertArrayEquals(new String[] { "a", "b c" }, split("a 'b c'")); assertArrayEquals(new String[] { "a", "b c" }, split("a 'b c'"));
assertArrayEquals(new String[] { "a", "b c" }, split("a \"b c\"")); assertArrayEquals(new String[] { "a", "b c" }, split("a \"b c\""));
assertArrayEquals(new String[] { "a", "b\\c" }, split("a \"b\\c\""));
} }
} }

Loading…
Cancel
Save