samg / diffy

Easy Diffing in Ruby
http://rubygems.org/gems/diffy
MIT License
1.26k stars 103 forks source link

HTML output ignoring new line diff? #110

Open ablce9 opened 4 years ago

ablce9 commented 4 years ago

Hi, first of all we really appreciate all of efforts diffy contributors are putting. Our product can not be thrived without diffy!

We have been noticing an unexpected behavior when comparing a text with a text containing a newline at end of file with HTML format like so:

[47] pry(main)> out = Diffy::SplitDiff.new("aaaaaaaaaa\n", "aaaaaaaaaa", format: :html, allow_empty_diff: false)
=> #<Diffy::SplitDiff:0x0000561b1cb964e0 @diff="<div class=\"diff\"></div>", @format=:html, @left_diff="<div class=\"diff\"></div>", @right_diff="<div class=\"diff\"></div>">
[48] pry(main)> out.right
=> "<div class=\"diff\"></div>"
[49] pry(main)> out.left
=> "<div class=\"diff\"></div>"
[50] pry(main)>

This is like saying there is no diffs even though left text does end with \n . Most importantly, characters disappear!

However, in TEXT format output is a bit different than that like so:

[45] pry(main)> Diffy::SplitDiff.new("aaaaaaaaaa\n", "aaaaaaaaaa", format: :text, allow_empty_diff: false)
=> #<Diffy::SplitDiff:0x0000561b1cb42660
 @diff="-aaaaaaaaaa\n" + "+aaaaaaaaaa\n" + "\\ No newline at end of file\n",
 @format=:text,
 @left_diff="-aaaaaaaaaa\n" + "\\ No newline at end of file\n",
 @right_diff="+aaaaaaaaaa\n" + "\\ No newline at end of file\n">

As you can see, both left and right diff are processed in text format, nicely denoting that No newline at end of file. We would expect the same, not empty html tags but actual newline diff with html tags.

Before specifying this kind of behavior is a bug, we would like to know this(comparing with a text with newline in HTML format) is expected or not.

Thanks

bv-dhritishman commented 3 years ago

Note that using format html_simple does not produce empty html tags, but the No newline message is not present.

[181] pry(main)> out = Diffy::SplitDiff.new("aaaaaaaaaa\n", "aaaaaaaaaa", format: :html_simple, allow_empty_diff: false)
=> #<Diffy::SplitDiff:0x00559873e4bb58
 @diff="<div class=\"diff\">\n  <ul>\n    <li class=\"del\"><del>aaaaaaaaaa</del></li>\n    <li class=\"ins\"><ins>aaaaaaaaaa</ins></li>\n\n  </ul>\n</div>\n",
 @format=:html_simple,
 @left_diff="<div class=\"diff\">\n  <ul>\n    <li class=\"del\"><del>aaaaaaaaaa</del></li>\n\n  </ul>\n</div>\n",
 @right_diff="<div class=\"diff\">\n  <ul>\n    <li class=\"ins\"><ins>aaaaaaaaaa</ins></li>\n\n  </ul>\n</div>\n">