Skip to content
Snippets Groups Projects

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

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

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
43 43 $hunkTarget = [];
44 44
45 45 for ($i = 0; $i < count($diff); $i++) {
46 // Ignore line end warnings.
47 if ($diff[$i][1] === Differ::DIFF_LINE_END_WARNING) {
48 // @todo maybe we can log them or report them somehow.
49 continue;
50 }
  • 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
  • added 1 commit

    • 0c97543c - Add coverage to DiffEngineTest

    Compare with previous version

  • Michael Strelan added 44 commits

    added 44 commits

    Compare with previous version

  • Please register or sign in to reply
    Loading