Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 667ad80

Browse files
authored
Merge pull request #378 from rspec/escape-slash-r
\r should be escaped when inside an array
2 parents 5cda28d + e47168f commit 667ad80

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

Changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
### Development
2+
3+
Bug Fixes:
4+
5+
* Escape \r when outputting strings inside arrays.
6+
(Tomita Masahiro, Jon Rowe, #378)
7+
18
### 3.8.2 / 2019-06-10
29
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.8.1...v3.8.2)
310

lib/rspec/support/differ.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def diffably_stringify(array)
9797
if Array === entry
9898
entry.inspect
9999
else
100-
entry.to_s.gsub("\n", "\\n")
100+
entry.to_s.gsub("\n", "\\n").gsub("\r", "\\r")
101101
end
102102
end
103103
end

spec/rspec/support/differ_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,17 @@ def inspect; "<BrokenObject>"; end
209209
expect(diff).to be_diffed_as(expected_diff)
210210
end
211211

212+
it 'outputs unified diff message of strings in arrays' do
213+
diff = differ.diff(["a\r\nb"], ["a\r\nc"])
214+
expected_diff = <<-EOD
215+
216+
@@ -1,2 +1,2 @@
217+
-a\\r\\nc
218+
+a\\r\\nb
219+
EOD
220+
expect(diff).to be_diffed_as(expected_diff)
221+
end
222+
212223
it "outputs unified diff message of two hashes" do
213224
expected = { :foo => 'bar', :baz => 'quux', :metasyntactic => 'variable', :delta => 'charlie', :width =>'quite wide' }
214225
actual = { :foo => 'bar', :metasyntactic => 'variable', :delta => 'charlotte', :width =>'quite wide' }

0 commit comments

Comments
 (0)