]> source.dussan.org Git - jgit.git/commitdiff
testMaliciousPathEmpty fails on Windows 63/17963/1
authorRobin Rosenberg <robin.rosenberg@dewire.com>
Fri, 1 Nov 2013 15:43:46 +0000 (16:43 +0100)
committerRobin Rosenberg <robin.rosenberg@dewire.com>
Fri, 1 Nov 2013 15:43:46 +0000 (16:43 +0100)
Checking of spaces at the end of the file name caused the
test to fail for Windows only.

Bug: 396662
Change-Id: I47bcccb0fa32ce606276c3f30d454851d115ca11
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java
org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java

index d263f629a5923a97358e6a6576481e56361ffe5e..b3219cddb5d1c4708a3a6d9c0eb12a27909ab4fe 100644 (file)
@@ -54,6 +54,7 @@ import org.eclipse.jgit.util.SystemReader;
 import org.junit.Test;
 
 public class DirCacheCheckoutMaliciousPathTest extends RepositoryTestCase {
+
        protected ObjectId theHead;
        protected ObjectId theMerge;
 
@@ -230,8 +231,14 @@ public class DirCacheCheckoutMaliciousPathTest extends RepositoryTestCase {
        }
 
        @Test
-       public void testMaliciousPathEmpty() throws Exception {
-               ((MockSystemReader) SystemReader.getInstance()).setCurrentPlatform();
+       public void testMaliciousPathEmptyUnix() throws Exception {
+               ((MockSystemReader) SystemReader.getInstance()).setUnix();
+               testMaliciousPathBadFirstCheckout("", "no");
+       }
+
+       @Test
+       public void testMaliciousPathEmptyWindows() throws Exception {
+               ((MockSystemReader) SystemReader.getInstance()).setWindows();
                testMaliciousPathBadFirstCheckout("", "no");
        }
 
index dd9ee10bf3bd85a91339d4bf7bd45c0afd03b6ce..bd896864d77166401a4568ab52ccc80462dc4520 100644 (file)
@@ -1202,8 +1202,9 @@ public class DirCacheCheckout {
                        // Space or period at end of file name is ignored by Windows.
                        // Treat this as a bad path for now. We may want to handle
                        // this as case insensitivity in the future.
-                       if (raw[ptr - 1] == '.' || raw[ptr - 1] == ' ')
-                               return false;
+                       if (ptr > 0)
+                               if (raw[ptr - 1] == '.' || raw[ptr - 1] == ' ')
+                                       return false;
                        int i;
                        // Bad names, eliminate suffix first
                        for (i = start; i < ptr; ++i)