Browse Source

Merge "Relax ObjectChecker to permit missing tagger lines"

stable-0.7
Robin Rosenberg 15 years ago committed by Code Review
parent
commit
94599930e7
  1. 31
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
  2. 47
      org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java
  3. 10
      org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java

31
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java

@ -1,5 +1,5 @@
/*
* Copyright (C) 2008, Google Inc.
* Copyright (C) 2008-2010, Google Inc.
* Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
* and other copyright owners as documented in the project's IP log.
*
@ -868,26 +868,7 @@ public class ObjectCheckerTest extends TestCase {
}
}
public void testInvalidTagNoTagHeader4() {
final StringBuilder b = new StringBuilder();
b.append("object ");
b.append("be9bfa841874ccc9f2ef7c48d0c76226f89b7189");
b.append('\n');
b.append("type commit\n");
b.append("tag foo");
final byte[] data = Constants.encodeASCII(b.toString());
try {
checker.checkTag(data);
fail("incorrectly accepted invalid tag");
} catch (CorruptObjectException e) {
assertEquals("no tagger header", e.getMessage());
}
}
public void testInvalidTagNoTaggerHeader1() {
public void testValidTagHasNoTaggerHeader() throws CorruptObjectException {
final StringBuilder b = new StringBuilder();
b.append("object ");
@ -897,13 +878,7 @@ public class ObjectCheckerTest extends TestCase {
b.append("type commit\n");
b.append("tag foo\n");
final byte[] data = Constants.encodeASCII(b.toString());
try {
checker.checkTag(data);
fail("incorrectly accepted invalid tag");
} catch (CorruptObjectException e) {
assertEquals("no tagger header", e.getMessage());
}
checker.checkTag(Constants.encodeASCII(b.toString()));
}
public void testInvalidTagInvalidTaggerHeader1() {

47
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java

@ -1,5 +1,5 @@
/*
* Copyright (C) 2008-2009, Google Inc.
* Copyright (C) 2008-2010, Google Inc.
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
@ -140,6 +140,51 @@ public class RevTagParseTest extends RepositoryTestCase {
assertEquals(taggerEmail, cTagger.getEmailAddress());
}
public void testParseOldStyleNoTagger() throws Exception {
final ObjectId treeId = id("9788669ad918b6fcce64af8882fc9a81cb6aba67");
final String name = "v1.2.3.4.5";
final String message = "test\n" //
+ "\n" //
+ "-----BEGIN PGP SIGNATURE-----\n" //
+ "Version: GnuPG v1.4.1 (GNU/Linux)\n" //
+ "\n" //
+ "iD8DBQBC0b9oF3Y\n" //
+ "-----END PGP SIGNATURE------n";
final StringBuilder body = new StringBuilder();
body.append("object ");
body.append(treeId.name());
body.append("\n");
body.append("type tree\n");
body.append("tag ");
body.append(name);
body.append("\n");
body.append("\n");
body.append(message);
final RevWalk rw = new RevWalk(db);
final RevTag c;
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
assertNull(c.getObject());
assertNull(c.getTagName());
c.parseCanonical(rw, body.toString().getBytes("UTF-8"));
assertNotNull(c.getObject());
assertEquals(treeId, c.getObject().getId());
assertSame(rw.lookupTree(treeId), c.getObject());
assertNotNull(c.getTagName());
assertEquals(name, c.getTagName());
assertEquals("test", c.getShortMessage());
assertEquals(message, c.getFullMessage());
assertNull(c.getTaggerIdent());
}
private RevTag create(final String msg) throws Exception {
final StringBuilder b = new StringBuilder();
b.append("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n");

10
org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java

@ -1,5 +1,5 @@
/*
* Copyright (C) 2008, Google Inc.
* Copyright (C) 2008-2010, Google Inc.
* Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
* and other copyright owners as documented in the project's IP log.
*
@ -217,10 +217,10 @@ public class ObjectChecker {
throw new CorruptObjectException("no tag header");
ptr = nextLF(raw, ptr);
if ((ptr = match(raw, ptr, tagger)) < 0)
throw new CorruptObjectException("no tagger header");
if ((ptr = personIdent(raw, ptr)) < 0 || raw[ptr++] != '\n')
throw new CorruptObjectException("invalid tagger");
if ((ptr = match(raw, ptr, tagger)) > 0) {
if ((ptr = personIdent(raw, ptr)) < 0 || raw[ptr++] != '\n')
throw new CorruptObjectException("invalid tagger");
}
}
private static int lastPathChar(final int mode) {

Loading…
Cancel
Save