diff options
author | Stan Hu <stanhu@gmail.com> | 2015-08-12 04:39:27 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2015-08-12 04:39:27 +0300 |
commit | c36adb98aa62a0f22f6ed290589cd2faf108abc4 (patch) | |
tree | 8be8a4afe35b4703ea1f3b68b36dd982aef828e9 /spec/lib | |
parent | cb6ad67f52c9e849e0f8ca34b2fff47c585bd816 (diff) |
Fix bug where backslashes in inline diffs could be dropped
Closes #2253
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/diff/inline_diff_spec.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/lib/gitlab/diff/inline_diff_spec.rb b/spec/lib/gitlab/diff/inline_diff_spec.rb new file mode 100644 index 00000000000..2e0a05088cc --- /dev/null +++ b/spec/lib/gitlab/diff/inline_diff_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper' + +describe Gitlab::InlineDiff do + describe '#processing' do + let(:diff) do + <<eos +--- a/test.rb ++++ b/test.rb +@@ -1,6 +1,6 @@ + class Test + def cleanup_string(input) + return nil if input.nil? +- input.sub(/[\\r\\n].+/,'').sub(/\\\\[rn].+/, '').strip ++ input.to_s.sub(/[\\r\\n].+/,'').sub(/\\\\[rn].+/, '').strip + end + end +eos + end + + let(:expected) do + ["--- a/test.rb\n", + "+++ b/test.rb\n", + "@@ -1,6 +1,6 @@\n", + " class Test\n", + " def cleanup_string(input)\n", + " return nil if input.nil?\n", + "- input.#!idiff-start!##!idiff-finish!#sub(/[\\r\\n].+/,'').sub(/\\\\[rn].+/, '').strip\n", + "+ input.#!idiff-start!#to_s.#!idiff-finish!#sub(/[\\r\\n].+/,'').sub(/\\\\[rn].+/, '').strip\n", + " end\n", + " end\n"] + end + + let(:subject) { Gitlab::InlineDiff.processing(diff.lines) } + + it 'should retain backslashes' do + expect(subject).to eq(expected) + end + end +end |