aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorMathias Kinzler <mathias.kinzler@sap.com>2010-09-01 09:13:19 +0200
committerMathias Kinzler <mathias.kinzler@sap.com>2010-09-01 09:13:19 +0200
commit2941d23e7ebaa524e7d9efbaf69565a57042d048 (patch)
tree1f2cbaa839f6fb49abc38a2bc2b1418449f9f92e /org.eclipse.jgit.test
parent6a05904e53bb60f96c344db33016b66f170cb9f0 (diff)
downloadjgit-2941d23e7ebaa524e7d9efbaf69565a57042d048.tar.gz
jgit-2941d23e7ebaa524e7d9efbaf69565a57042d048.zip
Avoid double quotes in Git Config
Currently, if a branch is created that has special chars ('#' in the bug), Config will surround the subsection name with double quotes during it's toText method which will result in an invalid file after saving the Config. Bug: 318249 Change-Id: I0a642f52def42d936869e4aaaeb6999567901001 Signed-off-by: Mathias Kinzler <mathias.kinzler@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java (renamed from org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryConfigTest.java)26
1 files changed, 25 insertions, 1 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
index 860d0d67f3..e12e869ec5 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
@@ -4,6 +4,7 @@
* Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com>
* Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
* Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
+ * Copyright (C) 2010, Mathias Kinzler <mathias.kinzler@sap.com>
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
@@ -47,6 +48,7 @@
package org.eclipse.jgit.lib;
+import java.text.MessageFormat;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Set;
@@ -61,7 +63,7 @@ import org.eclipse.jgit.util.SystemReader;
/**
* Test reading of git config
*/
-public class RepositoryConfigTest extends TestCase {
+public class ConfigTest extends TestCase {
public void test001_ReadBareKey() throws ConfigInvalidException {
final Config c = parse("[foo]\nbar\n");
assertEquals(true, c.getBoolean("foo", null, "bar", false));
@@ -351,6 +353,28 @@ public class RepositoryConfigTest extends TestCase {
assertTrue("Subsection should contain \"b\"", names.contains("b"));
}
+ public void testQuotingForSubSectionNames() {
+ String resultPattern = "[testsection \"{0}\"]\n\ttestname = testvalue\n";
+ String result;
+
+ Config config = new Config();
+ config.setString("testsection", "testsubsection", "testname",
+ "testvalue");
+
+ result = MessageFormat.format(resultPattern, "testsubsection");
+ assertEquals(result, config.toText());
+ config.clear();
+
+ config.setString("testsection", "#quotable", "testname", "testvalue");
+ result = MessageFormat.format(resultPattern, "#quotable");
+ assertEquals(result, config.toText());
+ config.clear();
+
+ config.setString("testsection", "with\"quote", "testname", "testvalue");
+ result = MessageFormat.format(resultPattern, "with\\\"quote");
+ assertEquals(result, config.toText());
+ }
+
private void assertReadLong(long exp) throws ConfigInvalidException {
assertReadLong(exp, String.valueOf(exp));
}