]> source.dussan.org Git - jgit.git/commitdiff
Config: Allow ending a file with "=" and no newline 70/49470/1
authorDave Borowitz <dborowitz@google.com>
Thu, 4 Jun 2015 18:48:46 +0000 (11:48 -0700)
committerDave Borowitz <dborowitz@google.com>
Thu, 4 Jun 2015 18:50:31 +0000 (11:50 -0700)
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

org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java

index 73e8a041baf95610062345bbf1fcdae3e4dc1d52..b90a0c467130a0410b163f0aa0147e2cd80ae2e7 100644 (file)
@@ -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));
        }
index fff82a32fa7677dfc63f6e2673a54870d39fa230..16953bb3406093319c9b3c03d5df887d075905d6 100644 (file)
@@ -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;
                        }