Browse Source

Config: Allow ending a file with "=" and no newline

This is a perfectly valid construction according to C git:

$ echo -en '[a]\nx =' > foo.config
$ git config -f foo.config a.x; echo $?

0

Change-Id: Icfcf8304adb43c79e2b8b998f8d651b2a94f6acb
stable-4.1
Dave Borowitz 10 years ago
parent
commit
b9f850a79b
  1. 9
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
  2. 2
      org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java

9
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java

@ -726,6 +726,15 @@ public class ConfigTest {
assertArrayEquals(new String[]{""}, c.getStringList("a", null, "x"));
}
@Test
public void testEmptyValueAtEof() throws Exception {
String text = "[a]\nx =";
Config c = parse(text);
assertEquals("", c.getString("a", null, "x"));
c = parse(text + "\n");
assertEquals("", c.getString("a", null, "x"));
}
private static void assertReadLong(long exp) throws ConfigInvalidException {
assertReadLong(exp, String.valueOf(exp));
}

2
org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java

@ -1200,8 +1200,6 @@ public class Config {
for (;;) {
int c = in.read();
if (c < 0) {
if (value.length() == 0)
throw new ConfigInvalidException(JGitText.get().unexpectedEndOfConfigFile);
break;
}

Loading…
Cancel
Save