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

Commit 52b07b4

Browse files
committed
\r should be escaped when inside an array
1 parent 5cda28d commit 52b07b4

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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)