From aa20faeaa5d1ab54dcf471e4ccb4c0e88be1ff9e Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 27 Apr 2020 14:15:29 -0700 Subject: [PATCH] Fix an invalid index access for synthetic lint inline comments from Harbormaster Summary: Ref T13524. If a Harbormaster lint message has no line number (which is permitted), we try to access an invalid index here. This is an exception after D21044. Treat comments with no line number as unchanged. These comments do not have "ghost" behavior and do not port across diffs. Test Plan: - Used "harbormaster.sendmessage" to submit lint with no line number on a changeset. - Viewed changeset. - Before patch: "Undefined index: " error. - After patch: Clean changeset with lint message. {F7400072} Maniphest Tasks: T13524 Differential Revision: https://secure.phabricator.com/D21178 --- .../parser/DifferentialChangesetParser.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/applications/differential/parser/DifferentialChangesetParser.php b/src/applications/differential/parser/DifferentialChangesetParser.php index 850a7e26d1..63a6c606c5 100644 --- a/src/applications/differential/parser/DifferentialChangesetParser.php +++ b/src/applications/differential/parser/DifferentialChangesetParser.php @@ -980,10 +980,15 @@ final class DifferentialChangesetParser extends Phobject { $new_side = $this->isCommentOnRightSideWhenDisplayed($comment); $line = $comment->getLineNumber(); - if ($new_side) { - $back_line = $new_backmap[$line]; + + // See T13524. Lint inlines from Harbormaster may not have a line + // number. + if ($line === null) { + $back_line = null; + } else if ($new_side) { + $back_line = idx($new_backmap, $line); } else { - $back_line = $old_backmap[$line]; + $back_line = idx($old_backmap, $line); } if ($back_line != $line) { @@ -1002,7 +1007,6 @@ final class DifferentialChangesetParser extends Phobject { $comment->setLineNumber($back_line); $comment->setLineLength(0); - } $start = max($comment->getLineNumber() - $lines_context, 0);