samg / diffy

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

Spaces in filepaths unsupported #29

Open arghorashy opened 11 years ago

arghorashy commented 11 years ago

I'm using diffy-2.1.2 with Ruby 1.9.3p327 (2012-11-10) [i386-mingw32] on Windows XP SP3.

For

Diffy::Diff.new(item, item2, :source => 'files')

where item and item2 are strings containing a path to files (at least one of which contains spaces), the following message is obtained:

C:\unixutils\diff.exe: extra operandto/file.ext' C:\unixutils\diff.exe: Try C:\unixutils\diff.exe --help' for more information.

Not a big deal because there is an easy work around:

content1="" content2="" File.open(item) {|f| content1 = f.read} File.open(item2) {|f| content2 = f.read} Diffy::Diff.new(content1, content2)

Grasswistle

samg commented 11 years ago

Looks like an issue that's only present on windows.

I just pushed a fix (1e99390) which I think will resolve this though I'm not able test it on Windows. Could you confirm that the fix works? You should be able to install the gem from github using the :git flag in your gemfile. (http://bundler.io/git.html)

bwl21 commented 11 years ago

This is actually a duplicate of #27 so I propose to close 27 as duplicate.

bwl21 commented 11 years ago

I performed rspec on windows. The issue with the whitespace in the path is gone, but we sill have two failing examples. running the spec on mac does not yield these problems:

with non valid UTF bytes
should not raise invalid encoding issues 0.01555s
expected: "-Foo ICS95095010000000000083320000BS01030000004100+\xFF00000000000000000\n+Bar ICS95095010000000000083320000BS01030000004100+\xFF00000000000000000\n"
     got: "-Foo ICS95095010000000000083320000BS01030000004100+\xFF00000000000000000\n+Bar ICS95095010000000000083320000BS01030000004100+\xFF00000000000000000\n" (using ==)
Diff:Could not produce a diff because the encoding of the actual string (ASCII-8BIT) differs from the encoding of the expected string (CP850)
./spec/diffy_spec.rb:109:in `block (4 levels) in <top (required)>'
107         DIFF
108         desired.force_encoding("ASCII-8BIT") if desired.respond_to?(:force_encoding)
109         Diffy::Diff.new(@path1, @path2, :source => 'files').to_s.should == desired
110       end
111     end
112# gem install syntax to get syntax highlighting

and

should highlight the changes within the line with windows style line breaks 0.01565s
expected: "<div class=\"diff\">\n  <ul>\n    <li class=\"unchanged\"><span>hahaha</span></li>\n    <li class=\"del\"><del><strong>time</strong> flies like a<strong>n arrow</strong></del></li>\n    <li class=\"del\"><del><strong>foo bar</strong></del></li>\n    <li class=\"ins\"><ins><strong>fruit</strong> flies like a<strong> banana</strong></ins></li>\n    <li class=\"unchanged\"><span>bang baz</span></li>\n  </ul>\n</div>\n"
     got: "<div class=\"diff\">\n  <ul>\n    <li class=\"unchanged\"><span>hahaha</span></li>\n    <li class=\"del\"><del>time flies like an arrow</del></li>\n    <li class=\"del\"><del>foo bar</del></li>\n    <li class=\"ins\"><ins>fruit flies like a banana</ins></li>\n    <li class=\"unchanged\"><span>bang baz</span></li>\n  </ul>\n</div>\n" (using ==)
Diff:
@@ -1,9 +1,9 @@
 <div class="diff">
   <ul>
     <li class="unchanged"><span>hahaha</span></li>
-    <li class="del"><del><strong>time</strong> flies like a<strong>n arrow</strong></del></li>
-    <li class="del"><del><strong>foo bar</strong></del></li>
-    <li class="ins"><ins><strong>fruit</strong> flies like a<strong> banana</strong></ins></li>
+    <li class="del"><del>time flies like an arrow</del></li>
+    <li class="del"><del>foo bar</del></li>
+    <li class="ins"><ins>fruit flies like a banana</ins></li>
     <li class="unchanged"><span>bang baz</span></li>
   </ul>
 </div>
./spec/diffy_spec.rb:471:in `block (4 levels) in <top (required)>'
469
470 HTML 471 @diff.to_s(:html).should == html 472 end 473 474# gem install syntax to get syntax highlighting