diff --git a/lib/gitlab/diff/highlight.rb b/lib/gitlab/diff/highlight.rb
index f940b57d596b9088a5044ef42860cd284180c019..e76a6f27856b526fc18ed09feca3c2021322833b 100644
--- a/lib/gitlab/diff/highlight.rb
+++ b/lib/gitlab/diff/highlight.rb
@@ -73,7 +73,7 @@ module Gitlab
 
           # Only update text if line is found. This will prevent
           # issues with submodules given the line only exists in diff content.
-          line.text = highlighted_line.gsub!(/\A\s/, line_prefix).html_safe if highlighted_line
+          line.text = highlighted_line.sub(/\A\s/, line_prefix).html_safe if highlighted_line
         end
 
         @lines