From 51d0e1f26e23d04ae73054958546159e01196a4d Mon Sep 17 00:00:00 2001 From: Dave Borowitz Date: Fri, 8 Feb 2013 11:35:20 -0800 Subject: [PATCH] Fix Config.fromText to not skip a last line with no newline Change-Id: Id6da6ff19296410806282bb7419fd8455e8c5475 --- .../tst/org/eclipse/jgit/lib/ConfigTest.java | 9 +++++++++ org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java index f07427313..e5e1e7ad6 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java @@ -556,6 +556,15 @@ public class ConfigTest { assertEquals(result, config.toText()); } + @Test + public void testNoFinalNewline() throws ConfigInvalidException { + Config c = parse("[a]\n" + + "x = 0\n" + + "y = 1"); + assertEquals("0", c.getString("a", null, "x")); + assertEquals("1", c.getString("a", null, "y")); + } + private static void assertReadLong(long exp) throws ConfigInvalidException { assertReadLong(exp, String.valueOf(exp)); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java index af04b1090..8240ac8f7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java @@ -1002,8 +1002,11 @@ public class Config { ConfigLine e = new ConfigLine(); for (;;) { int input = in.read(); - if (-1 == input) + if (-1 == input) { + if (e.section != null) + newEntries.add(e); break; + } final char c = (char) input; if ('\n' == c) {