aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2011-03-27 16:48:45 -0400
committerCode Review <codereview-daemon@eclipse.org>2011-03-27 16:48:45 -0400
commit6e10c1da0018d2be47e4a0ac06a18205e82da673 (patch)
tree2f5ccc7e08fdafb95f11692173906deb341719e6
parentfc5d521e4b3d378727f4649554cd62c56d8e0c02 (diff)
parenta327770433ef4495834c382f62aaeea75c847bbf (diff)
downloadjgit-6e10c1da0018d2be47e4a0ac06a18205e82da673.tar.gz
jgit-6e10c1da0018d2be47e4a0ac06a18205e82da673.zip
Merge "Fix: possible IndexOutOfBoundsException in ReflogReader"
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ReflogReaderTest.java22
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ReflogReader.java17
2 files changed, 28 insertions, 11 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ReflogReaderTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ReflogReaderTest.java
index 64333fc751..24c6aebaf2 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ReflogReaderTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ReflogReaderTest.java
@@ -83,6 +83,9 @@ public class ReflogReaderTest extends SampleDataRepositoryTestCase {
static byte[] headLine = "3333333333333333333333333333333333333333 3e7549db262d1e836d9bf0af7e22355468f1717c A U Thor <thor@committer.au> 1243028201 -0100\tbranch: change to HEAD\n"
.getBytes();
+ static byte[] oneLineWithoutComment = "da85355dfc525c9f6f3927b876f379f46ccf826e 3e7549db262d1e836d9bf0af7e22355468f1717c A O Thor Too <authortoo@wri.tr> 1243028200 +0200\n"
+ .getBytes();
+
@Test
public void testReadOneLine() throws Exception {
setupReflog("logs/refs/heads/master", oneLine);
@@ -185,6 +188,25 @@ public class ReflogReaderTest extends SampleDataRepositoryTestCase {
}
@Test
+ public void testReadLineWithMissingComment() throws Exception {
+ setupReflog("logs/refs/heads/master", oneLineWithoutComment);
+ final ReflogReader reader = db.getReflogReader("master");
+ Entry e = reader.getLastEntry();
+ assertEquals(ObjectId
+ .fromString("da85355dfc525c9f6f3927b876f379f46ccf826e"), e
+ .getOldId());
+ assertEquals(ObjectId
+ .fromString("3e7549db262d1e836d9bf0af7e22355468f1717c"), e
+ .getNewId());
+ assertEquals("A O Thor Too", e.getWho().getName());
+ assertEquals("authortoo@wri.tr", e.getWho().getEmailAddress());
+ assertEquals(120, e.getWho().getTimeZoneOffset());
+ assertEquals("2009-05-22T23:36:40", iso(e.getWho()));
+ assertEquals("",
+ e.getComment());
+ }
+
+ @Test
public void testNoLog() throws Exception {
assertEquals(0, db.getReflogReader("master").getReverseEntries().size());
assertNull(db.getReflogReader("master").getLastEntry());
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ReflogReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ReflogReader.java
index 75214308d6..ea2f73895d 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ReflogReader.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ReflogReader.java
@@ -88,18 +88,13 @@ public class ReflogReader {
JGitText.get().rawLogMessageDoesNotParseAsLogEntry);
}
who = RawParseUtils.parsePersonIdentOnly(raw, pos);
- int p0 = RawParseUtils.next(raw, pos, '\t'); // personident has no
- // \t
- if (p0 == -1) {
- throw new IllegalArgumentException(
- JGitText.get().rawLogMessageDoesNotParseAsLogEntry);
- }
- int p1 = RawParseUtils.nextLF(raw, p0);
- if (p1 == -1) {
- throw new IllegalArgumentException(
- JGitText.get().rawLogMessageDoesNotParseAsLogEntry);
+ int p0 = RawParseUtils.next(raw, pos, '\t');
+ if (p0 >= raw.length)
+ comment = ""; // personident has no \t, no comment present
+ else {
+ int p1 = RawParseUtils.nextLF(raw, p0);
+ comment = p1 > p0 ? RawParseUtils.decode(raw, p0, p1 - 1) : "";
}
- comment = RawParseUtils.decode(raw, p0, p1 - 1);
}
/**