samg / diffy

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

to_s(:html) mishandles \\n (backslash + en) #96

Open marlinpierce opened 6 years ago

marlinpierce commented 6 years ago

We have strings with a backslash (\) followed by the letter n, where the diff does not display correctly on our web site.

Apparently the diffy gem when using to_s(:html) is splitting a string with a backslash (\) character followed by an n character into two lines.

irb(main):001:0> puts Diffy::Diff.new("A\\nZ", "B\\nZ").to_s(:html)
<div class="diff">
  <ul>
    <li class="del"><del><strong>A</strong></del></li>
    <li class="del"><del>Z</del></li>
    <li class="ins"><ins><strong>B</strong></ins></li>
    <li class="ins"><ins>Z</ins></li>
  </ul>
</div>
=> nil
irb(main):002:0> puts Diffy::Diff.new("A\\\\nZ", "B\\\\nZ").to_s(:html)
<div class="diff">
  <ul>
    <li class="del"><del><strong>A</strong>\</del></li>
    <li class="del"><del>Z</del></li>
    <li class="ins"><ins><strong>B</strong>\</ins></li>
    <li class="ins"><ins>Z</ins></li>
  </ul>
</div>
=> nil

When there are two backslashes and an r, diffy gets completely confused.

irb(main):003:0> puts Diffy::Diff.new("A\\\\r\\\\nZ", "B\\\\r\\\\nZ").to_s(:html)
<div class="diff">
  <ul>
\</del></li>s="del"><del><strong>A</strong>\
    <li class="del"><del>Z</del></li>
\</ins></li>s="ins"><ins><strong>B</strong>\
    <li class="ins"><ins>Z</ins></li>
  </ul>
</div>
=> nil