Merge "Fix: possible IndexOutOfBoundsException in ReflogReader"
This commit is contained in:
commit
6e10c1da00
|
@ -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"
|
static byte[] headLine = "3333333333333333333333333333333333333333 3e7549db262d1e836d9bf0af7e22355468f1717c A U Thor <thor@committer.au> 1243028201 -0100\tbranch: change to HEAD\n"
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
|
static byte[] oneLineWithoutComment = "da85355dfc525c9f6f3927b876f379f46ccf826e 3e7549db262d1e836d9bf0af7e22355468f1717c A O Thor Too <authortoo@wri.tr> 1243028200 +0200\n"
|
||||||
|
.getBytes();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReadOneLine() throws Exception {
|
public void testReadOneLine() throws Exception {
|
||||||
setupReflog("logs/refs/heads/master", oneLine);
|
setupReflog("logs/refs/heads/master", oneLine);
|
||||||
|
@ -184,6 +187,25 @@ public void testReadRightLog() throws Exception {
|
||||||
.getLastEntry().getComment());
|
.getLastEntry().getComment());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Test
|
||||||
public void testNoLog() throws Exception {
|
public void testNoLog() throws Exception {
|
||||||
assertEquals(0, db.getReflogReader("master").getReverseEntries().size());
|
assertEquals(0, db.getReflogReader("master").getReverseEntries().size());
|
||||||
|
|
|
@ -88,18 +88,13 @@ static public class Entry {
|
||||||
JGitText.get().rawLogMessageDoesNotParseAsLogEntry);
|
JGitText.get().rawLogMessageDoesNotParseAsLogEntry);
|
||||||
}
|
}
|
||||||
who = RawParseUtils.parsePersonIdentOnly(raw, pos);
|
who = RawParseUtils.parsePersonIdentOnly(raw, pos);
|
||||||
int p0 = RawParseUtils.next(raw, pos, '\t'); // personident has no
|
int p0 = RawParseUtils.next(raw, pos, '\t');
|
||||||
// \t
|
if (p0 >= raw.length)
|
||||||
if (p0 == -1) {
|
comment = ""; // personident has no \t, no comment present
|
||||||
throw new IllegalArgumentException(
|
else {
|
||||||
JGitText.get().rawLogMessageDoesNotParseAsLogEntry);
|
|
||||||
}
|
|
||||||
int p1 = RawParseUtils.nextLF(raw, p0);
|
int p1 = RawParseUtils.nextLF(raw, p0);
|
||||||
if (p1 == -1) {
|
comment = p1 > p0 ? RawParseUtils.decode(raw, p0, p1 - 1) : "";
|
||||||
throw new IllegalArgumentException(
|
|
||||||
JGitText.get().rawLogMessageDoesNotParseAsLogEntry);
|
|
||||||
}
|
}
|
||||||
comment = RawParseUtils.decode(raw, p0, p1 - 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue