Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML output ignoring new line diff? #110

Open
ablce9 opened this issue Sep 9, 2020 · 1 comment
Open

HTML output ignoring new line diff? #110

ablce9 opened this issue Sep 9, 2020 · 1 comment

Comments

@ablce9
Copy link

ablce9 commented Sep 9, 2020

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
Copy link

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">

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants