From dd63f5cfc17d6f52a54e0c6442ea3bed42043b36 Mon Sep 17 00:00:00 2001
From: "Shawn O. Pearce" <spearce@spearce.org>
Date: Tue, 4 May 2010 16:25:20 -0700
Subject: [PATCH] Fix FooterLine.matches(FooterKey) on same length keys

If two keys are the same length, but don't share the same sequence
of characters, we were incorrectly claiming they still matched due
to a bug in the for loop condition.  I used the wrong variable and
the loop never executed, resulting in equality anytime the two keys
being compared were the same length.

Use the proper local variable to loop through the arrays, and add
a JUnit test to verify equality works as expected.

Change-Id: I4a02400e65a9b2e0da925b05a2cc4b579e1dd33a
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../eclipse/jgit/revwalk/FooterLineTest.java  | 20 +++++++++++++++++++
 .../org/eclipse/jgit/revwalk/FooterLine.java  |  2 +-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FooterLineTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FooterLineTest.java
index d199f04cc..9538a06b4 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FooterLineTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FooterLineTest.java
@@ -306,6 +306,26 @@ public void testFilterFootersIgnoreCase() {
 		assertEquals("Main Tain Er <mte@example.com>", footers.get(1));
 	}
 
+	public void testMatchesBugId() {
+		final RevCommit commit = parse("this is a commit subject for test\n"
+				+ "\n" // paragraph break, now footers appear in final block
+				+ "Simple-Bug-Id: 42\n");
+		final List<FooterLine> footers = commit.getFooterLines();
+
+		assertNotNull(footers);
+		assertEquals(1, footers.size());
+
+		final FooterLine line = footers.get(0);
+		assertNotNull(line);
+		assertEquals("Simple-Bug-Id", line.getKey());
+		assertEquals("42", line.getValue());
+
+		final FooterKey bugid = new FooterKey("Simple-Bug-Id");
+		assertTrue("matches Simple-Bug-Id", line.matches(bugid));
+		assertFalse("not Signed-off-by", line.matches(FooterKey.SIGNED_OFF_BY));
+		assertFalse("not CC", line.matches(FooterKey.CC));
+	}
+
 	private RevCommit parse(final String msg) {
 		final StringBuilder buf = new StringBuilder();
 		buf.append("tree " + ObjectId.zeroId().name() + "\n");
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FooterLine.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FooterLine.java
index 541f2748e..530200b0c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FooterLine.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FooterLine.java
@@ -90,7 +90,7 @@ public boolean matches(final FooterKey key) {
 		int bPtr = keyStart;
 		if (keyEnd - bPtr != len)
 			return false;
-		for (int kPtr = 0; bPtr < len;) {
+		for (int kPtr = 0; kPtr < len;) {
 			byte b = buffer[bPtr++];
 			if ('A' <= b && b <= 'Z')
 				b += 'a' - 'A';
-- 
GitLab