diff options
author | Stan Hu <stanhu@gmail.com> | 2015-08-11 18:39:27 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2015-08-11 18:39:27 -0700 |
commit | c36adb98aa62a0f22f6ed290589cd2faf108abc4 (patch) | |
tree | 8be8a4afe35b4703ea1f3b68b36dd982aef828e9 /lib | |
parent | cb6ad67f52c9e849e0f8ca34b2fff47c585bd816 (diff) | |
download | gitlab-ce-c36adb98aa62a0f22f6ed290589cd2faf108abc4.tar.gz |
Fix bug where backslashes in inline diffs could be dropped
Closes #2253
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/inline_diff.rb | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/gitlab/inline_diff.rb b/lib/gitlab/inline_diff.rb index 3517ecdf5cf..99e7b529ba9 100644 --- a/lib/gitlab/inline_diff.rb +++ b/lib/gitlab/inline_diff.rb @@ -46,8 +46,11 @@ module Gitlab end last_the_same_symbols += 1 last_token = first_line[last_the_same_symbols..-1] - diff_arr[index+1].sub!(/#{Regexp.escape(last_token)}$/, FINISH + last_token) - diff_arr[index+2].sub!(/#{Regexp.escape(last_token)}$/, FINISH + last_token) + # This is tricky: escape backslashes so that `sub` doesn't interpret them + # as backreferences. Regexp.escape does NOT do the right thing. + replace_token = FINISH + last_token.gsub(/\\/, '\&\&') + diff_arr[index+1].sub!(/#{Regexp.escape(last_token)}$/, replace_token) + diff_arr[index+2].sub!(/#{Regexp.escape(last_token)}$/, replace_token) end diff_arr end |