summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java120
1 files changed, 120 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
index 8a782b7ffd..c6578ccfae 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
@@ -1308,6 +1308,126 @@ public class ObjectCheckerTest {
}
@Test
+ public void testInvalidTreeNameIsMacHFSGit() {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 .gi\u200Ct");
+ byte[] data = Constants.encode(b.toString());
+ try {
+ checker.setSafeForMacOS(true);
+ checker.checkTree(data);
+ fail("incorrectly accepted an invalid tree");
+ } catch (CorruptObjectException e) {
+ assertEquals(
+ "invalid name '.gi\u200Ct' contains ignorable Unicode characters",
+ e.getMessage());
+ }
+ }
+
+ @Test
+ public void testInvalidTreeNameIsMacHFSGit2() {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 \u206B.git");
+ byte[] data = Constants.encode(b.toString());
+ try {
+ checker.setSafeForMacOS(true);
+ checker.checkTree(data);
+ fail("incorrectly accepted an invalid tree");
+ } catch (CorruptObjectException e) {
+ assertEquals(
+ "invalid name '\u206B.git' contains ignorable Unicode characters",
+ e.getMessage());
+ }
+ }
+
+ @Test
+ public void testInvalidTreeNameIsMacHFSGit3() {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 .git\uFEFF");
+ byte[] data = Constants.encode(b.toString());
+ try {
+ checker.setSafeForMacOS(true);
+ checker.checkTree(data);
+ fail("incorrectly accepted an invalid tree");
+ } catch (CorruptObjectException e) {
+ assertEquals(
+ "invalid name '.git\uFEFF' contains ignorable Unicode characters",
+ e.getMessage());
+ }
+ }
+
+ private static byte[] concat(byte[] b1, byte[] b2) {
+ byte[] data = new byte[b1.length + b2.length];
+ System.arraycopy(b1, 0, data, 0, b1.length);
+ System.arraycopy(b2, 0, data, b1.length, b2.length);
+ return data;
+ }
+
+ @Test
+ public void testInvalidTreeNameIsMacHFSGitCorruptUTF8AtEnd() {
+ byte[] data = concat(Constants.encode("100644 .git"),
+ new byte[] { (byte) 0xef });
+ StringBuilder b = new StringBuilder();
+ entry(b, "");
+ data = concat(data, Constants.encode(b.toString()));
+ try {
+ checker.setSafeForMacOS(true);
+ checker.checkTree(data);
+ fail("incorrectly accepted an invalid tree");
+ } catch (CorruptObjectException e) {
+ assertEquals(
+ "invalid name contains byte sequence '0xef' which is not a valid UTF-8 character",
+ e.getMessage());
+ }
+ }
+
+ @Test
+ public void testInvalidTreeNameIsMacHFSGitCorruptUTF8AtEnd2() {
+ byte[] data = concat(Constants.encode("100644 .git"), new byte[] {
+ (byte) 0xe2, (byte) 0xab });
+ StringBuilder b = new StringBuilder();
+ entry(b, "");
+ data = concat(data, Constants.encode(b.toString()));
+ try {
+ checker.setSafeForMacOS(true);
+ checker.checkTree(data);
+ fail("incorrectly accepted an invalid tree");
+ } catch (CorruptObjectException e) {
+ assertEquals(
+ "invalid name contains byte sequence '0xe2ab' which is not a valid UTF-8 character",
+ e.getMessage());
+ }
+ }
+
+ @Test
+ public void testInvalidTreeNameIsNotMacHFSGit()
+ throws CorruptObjectException {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 .git\u200Cx");
+ byte[] data = Constants.encode(b.toString());
+ checker.setSafeForMacOS(true);
+ checker.checkTree(data);
+ }
+
+ @Test
+ public void testInvalidTreeNameIsNotMacHFSGit2()
+ throws CorruptObjectException {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 .kit\u200C");
+ byte[] data = Constants.encode(b.toString());
+ checker.setSafeForMacOS(true);
+ checker.checkTree(data);
+ }
+
+ @Test
+ public void testInvalidTreeNameIsNotMacHFSGitOtherPlatform()
+ throws CorruptObjectException {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 .git\u200C");
+ byte[] data = Constants.encode(b.toString());
+ checker.checkTree(data);
+ }
+
+ @Test
public void testInvalidTreeNameIsDotGitDot() {
StringBuilder b = new StringBuilder();
entry(b, "100644 .git.");