diff options
author | Dave Borowitz <dborowitz@google.com> | 2017-11-20 13:55:25 -0500 |
---|---|---|
committer | Dave Borowitz <dborowitz@google.com> | 2017-11-20 13:55:25 -0500 |
commit | 8b3ab4343c4d34993176b5fa799a039e8114054b (patch) | |
tree | beeae1ed88b0253c579e81c5586204cb4e350dbe /org.eclipse.jgit.test | |
parent | 3efea067a3db7e3bdfadd47d5420deaf9a35d740 (diff) | |
download | jgit-8b3ab4343c4d34993176b5fa799a039e8114054b.tar.gz jgit-8b3ab4343c4d34993176b5fa799a039e8114054b.zip |
Config: Handle leading/trailing single whitespaces
Change-Id: I468106acd2006d0a174c76dfd4bce231f1c7a6f8
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java | 52 |
1 files changed, 52 insertions, 0 deletions
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 e9505f67d0..748848e97f 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 @@ -965,4 +965,56 @@ public class ConfigTest { expectedEx.expect(IllegalArgumentException.class); parseTime("-1", MILLISECONDS); } + + @Test + public void testEscapeSpacesOnly() throws ConfigInvalidException { + assertEquals("", Config.escapeValue("")); + assertEquals("\" \"", Config.escapeValue(" ")); + assertEquals("\" \"", Config.escapeValue(" ")); + + assertParseRoundTrip(" "); + assertParseRoundTrip(" "); + } + + @Test + public void testEscapeLeadingSpace() throws ConfigInvalidException { + assertEquals("x", Config.escapeValue("x")); + assertEquals("\" x\"", Config.escapeValue(" x")); + assertEquals("\" x\"", Config.escapeValue(" x")); + + assertParseRoundTrip("x"); + assertParseRoundTrip(" x"); + assertParseRoundTrip(" x"); + } + + @Test + public void testEscapeTrailingSpace() throws ConfigInvalidException { + assertEquals("x", Config.escapeValue("x")); + assertEquals("\"x \"", Config.escapeValue("x ")); + assertEquals("x\" \"", Config.escapeValue("x ")); + + assertParseRoundTrip("x"); + assertParseRoundTrip("x "); + assertParseRoundTrip("x "); + } + + @Test + public void testEscapeLeadingAndTrailingSpace() + throws ConfigInvalidException { + assertEquals("\" x \"", Config.escapeValue(" x ")); + assertEquals("\" x \"", Config.escapeValue(" x ")); + assertEquals("\" x \"", Config.escapeValue(" x ")); + assertEquals("\" x \"", Config.escapeValue(" x ")); + + assertParseRoundTrip(" x "); + assertParseRoundTrip(" x "); + assertParseRoundTrip(" x "); + assertParseRoundTrip(" x "); + } + + private static void assertParseRoundTrip(String value) + throws ConfigInvalidException { + Config c = parse("[foo]\nbar = " + Config.escapeValue(value)); + assertEquals(value, c.getString("foo", null, "bar")); + } } |