diff options
author | Shawn Pearce <sop@google.com> | 2014-11-25 11:43:32 -0800 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2014-12-18 14:48:46 +0100 |
commit | 8d36fa343c689d1334ddc1f722c153203c1d13f7 (patch) | |
tree | b9e33c3c41a93bc06b03d170ad72e2c9738c24d9 /org.eclipse.jgit.test/tst | |
parent | d547d0c44b061c0d4e59629588b3074d90747e2d (diff) | |
download | jgit-8d36fa343c689d1334ddc1f722c153203c1d13f7.tar.gz jgit-8d36fa343c689d1334ddc1f722c153203c1d13f7.zip |
DirCache: Refuse to read files with invalid paths
If the DirCache contains a path that is known to be invalid, refuse to
read the DirCache into memory. This avoids confusing errors later if
an invalid path read from the DirCache were to be passed into a new
DirCacheEntry constructor.
Change-Id: Ic033d81e23a5fbd554cc4dff80a232504562ffa8
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java index 08957d7fb3..0c1baab2b8 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java @@ -47,12 +47,19 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.File; +import java.text.MessageFormat; +import org.eclipse.jgit.errors.CorruptObjectException; +import org.eclipse.jgit.internal.JGitText; +import org.eclipse.jgit.junit.MockSystemReader; import org.eclipse.jgit.junit.RepositoryTestCase; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.FileMode; +import org.eclipse.jgit.lib.ObjectInserter; +import org.eclipse.jgit.util.SystemReader; import org.junit.Test; public class DirCacheBasicTest extends RepositoryTestCase { @@ -234,4 +241,41 @@ public class DirCacheBasicTest extends RepositoryTestCase { final byte[] path = Constants.encode("a"); assertEquals(-1, dc.findEntry(path, path.length)); } + + @Test + public void testRejectInvalidWindowsPaths() throws Exception { + SystemReader.setInstance(new MockSystemReader() { + { + setUnix(); + } + }); + + String path = "src/con.txt"; + DirCache dc = db.lockDirCache(); + DirCacheBuilder b = dc.builder(); + DirCacheEntry e = new DirCacheEntry(path); + e.setFileMode(FileMode.REGULAR_FILE); + e.setObjectId(new ObjectInserter.Formatter().idFor( + Constants.OBJ_BLOB, + Constants.encode(path))); + b.add(e); + b.commit(); + db.readDirCache(); + + SystemReader.setInstance(new MockSystemReader() { + { + setWindows(); + } + }); + + try { + db.readDirCache(); + fail("should have rejected " + path); + } catch (CorruptObjectException err) { + assertEquals(MessageFormat.format(JGitText.get().invalidPath, path), + err.getMessage()); + assertNotNull(err.getCause()); + assertEquals("invalid name 'CON'", err.getCause().getMessage()); + } + } } |