diff options
author | Thomas Wolf <thomas.wolf@paranor.ch> | 2019-10-28 18:11:57 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2019-11-15 15:12:23 -0800 |
commit | 345e2648df3e17bd18d0f4251774d3f8b298f77c (patch) | |
tree | 91fa14f76c0b06b281b64e3f7a9fa3320ca50120 /org.eclipse.jgit.test | |
parent | a227dc3ba0e0a426657b84cea148174e8a315b31 (diff) | |
download | jgit-345e2648df3e17bd18d0f4251774d3f8b298f77c.tar.gz jgit-345e2648df3e17bd18d0f4251774d3f8b298f77c.zip |
DiffFormatter: support core.quotePath = false
core.quotePath = false means that "bytes higher than 0x80 are not
considered "unusal" anymore"[1], i.e., they are not escaped. In
essence this preserves non-ASCII characters in path names in output.
Note that control characters and other special characters in the
ASCII range will still be escaped.
Add a new QuotedString.GIT_PATH_MINIMAL singleton implementing this.
Change the normal GIT_PATH algorithm to use bytes instead of characters
so it can be re-used. Provide a setter in DiffFormatter for the quoting
style so that an application can override the default, which is the
setting from the git config (and by default "true"). Use the new
QuotedString.GIT_PATH_MINIMAL when core.quotePath == false.
[1] https://git-scm.com/docs/git-config#Documentation/git-config.txt-corequotePath
Bug: 552467
Change-Id: Ifcb233e7d10676333bf42011e32d01a4e1138059
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringGitPathStyleTest.java | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringGitPathStyleTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringGitPathStyleTest.java index 9a0c96e171..c09b136ca6 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringGitPathStyleTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringGitPathStyleTest.java @@ -45,6 +45,7 @@ package org.eclipse.jgit.util; import static java.nio.charset.StandardCharsets.ISO_8859_1; import static org.eclipse.jgit.util.QuotedString.GIT_PATH; +import static org.eclipse.jgit.util.QuotedString.GIT_PATH_MINIMAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; @@ -67,6 +68,12 @@ public class QuotedStringGitPathStyleTest { assertEquals(exp, r); } + private static void assertDequoteMinimal(String exp, String in) { + final byte[] b = ('"' + in + '"').getBytes(ISO_8859_1); + final String r = GIT_PATH_MINIMAL.dequote(b, 0, b.length); + assertEquals(exp, r); + } + @Test public void testQuote_Empty() { assertEquals("\"\"", GIT_PATH.quote("")); @@ -206,4 +213,75 @@ public class QuotedStringGitPathStyleTest { assertSame("abc@2x.png", GIT_PATH.quote("abc@2x.png")); assertDequote("abc@2x.png", "abc\\1002x.png"); } + + @Test + public void testNoQuote() { + assertSame("\u00c5ngstr\u00f6m", + GIT_PATH_MINIMAL.quote("\u00c5ngstr\u00f6m")); + } + + @Test + public void testQuoteMinimal() { + assertEquals("\"\u00c5n\\\\str\u00f6m\"", + GIT_PATH_MINIMAL.quote("\u00c5n\\str\u00f6m")); + } + + @Test + public void testDequoteMinimal() { + assertEquals("\u00c5n\\str\u00f6m", GIT_PATH_MINIMAL + .dequote(GIT_PATH_MINIMAL.quote("\u00c5n\\str\u00f6m"))); + + } + + @Test + public void testRoundtripMinimal() { + assertEquals("\u00c5ngstr\u00f6m", GIT_PATH_MINIMAL + .dequote(GIT_PATH_MINIMAL.quote("\u00c5ngstr\u00f6m"))); + + } + + @Test + public void testQuoteMinimalDequoteNormal() { + assertEquals("\u00c5n\\str\u00f6m", GIT_PATH + .dequote(GIT_PATH_MINIMAL.quote("\u00c5n\\str\u00f6m"))); + + } + + @Test + public void testQuoteNormalDequoteMinimal() { + assertEquals("\u00c5n\\str\u00f6m", GIT_PATH_MINIMAL + .dequote(GIT_PATH.quote("\u00c5n\\str\u00f6m"))); + + } + + @Test + public void testRoundtripMinimalDequoteNormal() { + assertEquals("\u00c5ngstr\u00f6m", + GIT_PATH.dequote(GIT_PATH_MINIMAL.quote("\u00c5ngstr\u00f6m"))); + + } + + @Test + public void testRoundtripNormalDequoteMinimal() { + assertEquals("\u00c5ngstr\u00f6m", + GIT_PATH_MINIMAL.dequote(GIT_PATH.quote("\u00c5ngstr\u00f6m"))); + + } + + @Test + public void testDequote_UTF8_Minimal() { + assertDequoteMinimal("\u00c5ngstr\u00f6m", + "\\303\\205ngstr\\303\\266m"); + } + + @Test + public void testDequote_RawUTF8_Minimal() { + assertDequoteMinimal("\u00c5ngstr\u00f6m", "\303\205ngstr\303\266m"); + } + + @Test + public void testDequote_RawLatin1_Minimal() { + assertDequoteMinimal("\u00c5ngstr\u00f6m", "\305ngstr\366m"); + } + } |