Skip to content

Commit

Permalink
Add option :ignore_crlf to fix samg#105
Browse files Browse the repository at this point in the history
  • Loading branch information
ptyagi16 committed Oct 1, 2019
1 parent fbfc4e0 commit 6c4650b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/diffy/html_formatter.rb
Expand Up @@ -90,10 +90,14 @@ def highlighted_words

def split_characters(chunk)
chunk.gsub(/^./, '').each_line.map do |line|
chars = line.sub(/([\r\n]$)/, '').split('')
# add escaped newlines
chars << '\n'
chars.map{|chr| ERB::Util.h(chr) }
if @options[:ignore_crlf]
(line.chomp.split('') + ['\n']).map{|chr| ERB::Util.h(chr) }
else
chars = line.sub(/([\r\n]$)/, '').split('')
# add escaped newlines
chars << '\n'
chars.map{|chr| ERB::Util.h(chr) }
end
end.flatten.join("\n") + "\n"
end

Expand Down
7 changes: 7 additions & 0 deletions spec/diffy_spec.rb
Expand Up @@ -503,6 +503,13 @@ def tempfile(string, fn = 'diffy-spec')
expect(@diff.to_s(:html)).to eq(html)
end

it "should treat unix vs windows newlines as same if option :ignore_crlf" do
@diff = Diffy::Diff.new("one\ntwo\nthree\n", "one\r\ntwo\r\nthree\r\n",
ignore_crlf: true)
empty_diff = "<div class=\"diff\"></div>"
expect(@diff.to_s(:html)).to eq(empty_diff)
end

describe 'with lines that include \n' do
before do
string1 = 'a\nb'"\n"
Expand Down

0 comments on commit 6c4650b

Please sign in to comment.