Browse Source

testMaliciousPathEmpty fails on Windows

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>
stable-3.2
Robin Rosenberg 11 years ago
parent
commit
98bc384d2b
  1. 11
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java
  2. 1
      org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java

11
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java

@ -54,6 +54,7 @@ import org.eclipse.jgit.util.SystemReader;
import org.junit.Test; import org.junit.Test;
public class DirCacheCheckoutMaliciousPathTest extends RepositoryTestCase { public class DirCacheCheckoutMaliciousPathTest extends RepositoryTestCase {
protected ObjectId theHead; protected ObjectId theHead;
protected ObjectId theMerge; protected ObjectId theMerge;
@ -230,8 +231,14 @@ public class DirCacheCheckoutMaliciousPathTest extends RepositoryTestCase {
} }
@Test @Test
public void testMaliciousPathEmpty() throws Exception { public void testMaliciousPathEmptyUnix() throws Exception {
((MockSystemReader) SystemReader.getInstance()).setCurrentPlatform(); ((MockSystemReader) SystemReader.getInstance()).setUnix();
testMaliciousPathBadFirstCheckout("", "no");
}
@Test
public void testMaliciousPathEmptyWindows() throws Exception {
((MockSystemReader) SystemReader.getInstance()).setWindows();
testMaliciousPathBadFirstCheckout("", "no"); testMaliciousPathBadFirstCheckout("", "no");
} }

1
org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java vendored

@ -1202,6 +1202,7 @@ public class DirCacheCheckout {
// Space or period at end of file name is ignored by Windows. // 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 // Treat this as a bad path for now. We may want to handle
// this as case insensitivity in the future. // this as case insensitivity in the future.
if (ptr > 0)
if (raw[ptr - 1] == '.' || raw[ptr - 1] == ' ') if (raw[ptr - 1] == '.' || raw[ptr - 1] == ' ')
return false; return false;
int i; int i;

Loading…
Cancel
Save