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

Change-Id: Ia6a56512baa6a0f27e2eef1b19ebb60291ba377f
Signed-off-by: Rüdiger Herrmann <ruediger.herrmann@gmx.de>
This commit is contained in:
Rüdiger Herrmann 2016-05-21 15:19:24 +02:00 committed by David Pursehouse
parent 03046d0f60
commit a5eccf4a4d
2 changed files with 3 additions and 1 deletions

View File

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

View File

@ -51,9 +51,11 @@ public class CLIGitCommandTest {
@Test
public void testSplit() throws Exception {
assertArrayEquals(new String[0], split(""));
assertArrayEquals(new String[] { "a" }, split("a"));
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\""));
}
}