diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-08-18 02:33:36 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-08-18 02:33:36 +0300 |
commit | c9920c422d55680310cffcf34432d708de4bf207 (patch) | |
tree | 1e37ea6e18772ea8de89f0b8ba8032c2873c76ab /spec/lib | |
parent | f4cb6e438ab3cb03589c5ba36dc2b23c78b66c5a (diff) | |
parent | c36adb98aa62a0f22f6ed290589cd2faf108abc4 (diff) |
Merge branch 'fix-backslashes-inline-diff' into 'master'
Fix bug where backslashes in inline diffs could be dropped
This MR fixes a bug in inline diff generation causing backslashes to be dropped. For example, the input:
```
input.to_s.sub(/[\r\n].+/,'').sub(/\\[rn].+/, '').strip
```
The second backslash is dropped in the second `sub` statement:
![image](https://gitlab.com/gitlab-org/gitlab-ce/uploads/16e513894f7ecda1b111fe7d43e7f388/image.png)
With this fix, it looks like:
![image](https://gitlab.com/gitlab-org/gitlab-ce/uploads/90fd635a937a68f1b2403740ebc75e3a/image.png)
Closes #2253
See merge request !1143
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 |