]> source.dussan.org Git - jgit.git/commitdiff
Fix ObjectChecker when normalization is enabled 10/24410/2
authorShawn Pearce <spearce@spearce.org>
Thu, 3 Apr 2014 17:24:49 +0000 (10:24 -0700)
committerShawn Pearce <spearce@spearce.org>
Thu, 3 Apr 2014 18:15:25 +0000 (11:15 -0700)
When safeForMacOS is enabled the checker verifies a name does not
match against another name in the same tree after normalization to
NFC. The check was incorrect and failed when the first name was put
in, rejecting simple trees containing only one file like "F".

Add a test for this simple tree to verify it is accepted.
Fix the test for NFC normalization to actually normalize
and have a collision.

Change-Id: I39e7d71150948872bff6cd2b06bf8dae52aa3c33

org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java

index 3f58b7501f2438b04fea777db835d343f1e9c092..9fc7fca987144310e62ba063574980792e8ab307 100644 (file)
@@ -1493,8 +1493,8 @@ public class ObjectCheckerTest {
                }
 
                StringBuilder b = new StringBuilder();
-               entry(b, "100644 \u00C1");
-               entry(b, "100644 \u004a\u0301");
+               entry(b, "100644 \u0065\u0301");
+               entry(b, "100644 \u00e9");
                byte[] data = b.toString().getBytes("UTF-8");
                try {
                        checker.setSafeForMacOS(true);
@@ -1505,6 +1505,15 @@ public class ObjectCheckerTest {
                }
        }
 
+       @Test
+       public void testInvalidTreeDuplicateNames8()
+                       throws UnsupportedEncodingException, CorruptObjectException {
+               StringBuilder b = new StringBuilder();
+               entry(b, "100644 A");
+               checker.setSafeForMacOS(true);
+               checker.checkTree(b.toString().getBytes("UTF-8"));
+       }
+
        @Test
        public void testRejectNulInPathSegment() {
                try {
index 1b135a924c62865a46c5225905b95864bec91c2b..d8a70c104f04ea53d0faddecbaf41766a9dd6fae 100644 (file)
@@ -382,7 +382,7 @@ public class ObjectChecker {
                                throw new CorruptObjectException("truncated in name");
                        checkPathSegment2(raw, thisNameB, ptr);
                        if (normalized != null) {
-                               if (normalized.add(normalize(raw, thisNameB, ptr)))
+                               if (!normalized.add(normalize(raw, thisNameB, ptr)))
                                        throw new CorruptObjectException("duplicate entry names");
                        } else if (duplicateName(raw, thisNameB, ptr))
                                throw new CorruptObjectException("duplicate entry names");