Skip to content

Fix "extra newline for files with Windows line endings"

What does this MR do?

Normalizes line encodings when formatting a file preview to avoid the windows line encoding issue described in (#20440 (closed)).

Are there points in the code the reviewer needs to double check?

I had considered updating the github_git gem to add the option to scrub all CRLF line encodings, however adding this conversion to Gitlab::Highlight.highlight() seemed like a better place to address this issue. This way raw file blobs and raw diffs will still retain their original encoding, but the odd formatting is eliminated when viewing these are embedded in a page like /my-org/my-project/commit/830ade3e or /my-org/my-project/merge_requests/1234/diffs.

Let me know if you think there's a better solution for this.

Why was this MR needed?

Windows line encodings are causing extra lines to appear when formatted.

example vs: example2

What are the relevant issue numbers?

#20440 (closed)

Does this MR meet the acceptance criteria?

Merge request reports