Misleading suggestion is created when made at the last line of a file with "\ No newline at end of file"

Problem:

When sending a comment to a line that has no breakline at the end (normally the last line of a file), that's what happens:

Screenshot_2019-09-16_10.30.57

Note that the old/new content became mixed together as a big deletion, which is wrong. That's mainly a presentation problem.

What happens is that we build diff lines with a concatecation of from_content and to_content. Since the last line of from_content has no breakline, it breaks our diff lines builder for the suggestion.

Solution:

Initial test change I made was:

diff --git a/lib/gitlab/diff/suggestion_diff.rb b/lib/gitlab/diff/suggestion_diff.rb
index ee153c226b7..7f0a73b8edc 100644
--- a/lib/gitlab/diff/suggestion_diff.rb
+++ b/lib/gitlab/diff/suggestion_diff.rb
@@ -18,7 +18,7 @@ module Gitlab
       private

       def raw_diff
-        "#{diff_header}\n#{from_content_as_diff}#{to_content_as_diff}"
+        "#{diff_header}\n#{from_content_as_diff}\n#{to_content_as_diff}"
       end

       def diff_header

Though ideally we'll need to do the following when building the diff:

  1. Check if from_content_as_diff has a breakline, in that case, do nothing
  2. If the has no breakline, add it to the end of from_content_as_diff

This process will keep persistence untouched (which is correct), but fix the presentation.

Assignee Loading
Time tracking Loading