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>
This commit is contained in:
Robin Rosenberg 2013-11-01 16:43:46 +01:00
parent e649287502
commit 98bc384d2b
2 changed files with 12 additions and 4 deletions

View File

@ -54,6 +54,7 @@
import org.junit.Test;
public class DirCacheCheckoutMaliciousPathTest extends RepositoryTestCase {
protected ObjectId theHead;
protected ObjectId theMerge;
@ -230,8 +231,14 @@ public void testMaliciousPathDot() throws Exception {
}
@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");
}

View File

@ -1202,8 +1202,9 @@ private static boolean isValidPathSegment(CanonicalTreeParser t) {
// 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)