Handle change subjects containing '\r' in NoteDb

JGit's RevCommit#getShortMessage() might return a subject containing
"\r\r". If we put this in the Subject footer of a NoteDb commit, which
we do in the commit that creates the patch set, then
RevCommit#getFooterLines() will treat "\r\r" as a new paragraph,
resulting in ignoring some footers.

Fix this by sanitizing '\r' to ' ', along with '\n' and '\0', which were
already sanitized in other contexts.

Change-Id: I449eded06ecbf713dd073f2d8c77dca721ba3d23
This commit is contained in:
Dave Borowitz
2017-02-05 16:13:59 -05:00
committed by Edwin Kempin
parent 49df12cb7d
commit 4e1f02db91
5 changed files with 88 additions and 6 deletions

View File

@@ -247,6 +247,55 @@ public class ChangeBundleTest extends GerritBaseTests {
assertNoDiffs(b2, b1);
}
@Test
public void diffChangesSanitizesSubjectsBeforeComparison() throws Exception {
Change c1 = TestChanges.newChange(new Project.NameKey("project"), new Account.Id(100));
c1.setCurrentPatchSet(c1.currentPatchSetId(), "Subject\r\rbody", "Original");
Change c2 = clone(c1);
c2.setCurrentPatchSet(c2.currentPatchSetId(), "Subject body", "Original");
// Both ReviewDb, exact match required
ChangeBundle b1 =
new ChangeBundle(
c1, messages(), patchSets(), approvals(), comments(), reviewers(), REVIEW_DB);
ChangeBundle b2 =
new ChangeBundle(
c2, messages(), patchSets(), approvals(), comments(), reviewers(), REVIEW_DB);
assertDiffs(
b1,
b2,
"subject differs for Change.Id "
+ c1.getId()
+ ":"
+ " {Subject\r\rbody} != {Subject body}");
// Both NoteDb, exact match required (although it should be impossible to
// create a NoteDb change with '\r' in the subject).
b1 =
new ChangeBundle(
c1, messages(), patchSets(), approvals(), comments(), reviewers(), NOTE_DB);
b2 =
new ChangeBundle(
c2, messages(), patchSets(), approvals(), comments(), reviewers(), NOTE_DB);
assertDiffs(
b1,
b2,
"subject differs for Change.Id "
+ c1.getId()
+ ":"
+ " {Subject\r\rbody} != {Subject body}");
// One ReviewDb, one NoteDb, '\r' is normalized to ' '.
b1 =
new ChangeBundle(
c1, messages(), patchSets(), approvals(), comments(), reviewers(), REVIEW_DB);
b2 =
new ChangeBundle(
c2, messages(), patchSets(), approvals(), comments(), reviewers(), NOTE_DB);
assertNoDiffs(b1, b2);
assertNoDiffs(b2, b1);
}
@Test
public void diffChangesConsidersEmptyReviewDbTopicEquivalentToNullInNoteDb() throws Exception {
Change c1 = TestChanges.newChange(new Project.NameKey("project"), new Account.Id(100));