Skip to content
Snippets Groups Projects

Issue #3389715: DiffOpOutputBuilder::hunkOp does not handle Differ::DIFF_LINE_END_WARNING

Open Issue #3389715: DiffOpOutputBuilder::hunkOp does not handle Differ::DIFF_LINE_END_WARNING

Files

+ 5
0
@@ -43,6 +43,11 @@ public function toOpsArray(array $diff): array {
$hunkTarget = [];
for ($i = 0; $i < count($diff); $i++) {
// Ignore line end warnings.
if ($diff[$i][1] === Differ::DIFF_LINE_END_WARNING) {
// @todo maybe we can log them or report them somehow.
continue;
}
    • Comment on lines +46 to +50

      It's worth noting how \SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder handles this:

      for ($i = $diffStartIndex; $i < $diffEndIndex; ++$i) {
          if ($diff[$i][1] === Differ::ADDED) {
              fwrite($output, '+' . $diff[$i][0]);
          } elseif ($diff[$i][1] === Differ::REMOVED) {
              fwrite($output, '-' . $diff[$i][0]);
          } elseif ($diff[$i][1] === Differ::OLD) {
              fwrite($output, ' ' . $diff[$i][0]);
          } elseif ($diff[$i][1] === Differ::NO_LINE_END_EOF_WARNING) {
              fwrite($output, "\n"); // $diff[$i][0]
          } else { /* Not changed (old) Differ::OLD or Warning Differ::DIFF_LINE_END_WARNING */
              fwrite($output, ' ' . $diff[$i][0]);
          }
      }

      Essentially treats the warning as "not changed".

      We may also want to handle "Differ::NO_LINE_END_EOF_WARNING".

      • should we handle that here too then?

      • It seems the only usage of \SebastianBergmann\Diff\Differ::NO_LINE_END_EOF_WARNING is in \SebastianBergmann\Diff\Output\StrictUnifiedDiffOutputBuilder and \SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder, neither of which are used in core. This means we will never see this warning.

        This differs from \SebastianBergmann\Diff\Differ::DIFF_LINE_END_WARNING as that is called from \SebastianBergmann\Diff\Differ::diffToArray which is called in \Drupal\Component\Diff\Diff::__construct.

        I think we can leave it as is for now where \Drupal\Component\Diff\DiffOpOutputBuilder::hunkOp will throw an InvalidArgumentException.

      • Please register or sign in to reply
Please register or sign in to reply
// Handle a sequence of removals + additions as a sequence of changes, and
// manages the tail if required.
Loading