diffy 3.1.0 → 3.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +12 -5
- data/CHANGELOG +19 -0
- data/CONTRIBUTORS +3 -0
- data/Gemfile +1 -4
- data/README.md +17 -18
- data/Rakefile +2 -0
- data/diffy.gemspec +1 -1
- data/lib/diffy/diff.rb +30 -23
- data/lib/diffy/format.rb +1 -1
- data/lib/diffy/html_formatter.rb +8 -4
- data/lib/diffy/version.rb +1 -1
- data/spec/diffy_spec.rb +33 -2
- metadata +10 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 107dc73001f2e00bccf4b4f89a15ba86d045511f125f33bc8ed8987e239b5079
|
4
|
+
data.tar.gz: 0a07b298ff5eec7bcbf83adb0e3fa3c59c122796693d75e18d81d9ccfcb131de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47df78d6118935280b9011a77bb0c888da50af9dfac81dd810ca522cf23ad0099b50411a27e2ca57eac0369cb9fd9d82b97ce56525093002f2845d5d8e2e8121
|
7
|
+
data.tar.gz: fca9f15d0cd9cca745caa12f59da048f6bd4c62a572abd9987530ef3acacbdf228c78140c3305f618b86dc57a2a50a25fb0336e325f33afd5261c0a47e28f73c
|
data/.travis.yml
CHANGED
@@ -1,8 +1,15 @@
|
|
1
1
|
language: ruby
|
2
|
+
sudo: false
|
3
|
+
cache: bundler
|
2
4
|
rvm:
|
3
5
|
- 1.8.7
|
4
|
-
- 1.9.
|
5
|
-
-
|
6
|
-
- 2.
|
7
|
-
- 2.
|
8
|
-
- 2.
|
6
|
+
- 1.9.3-p551
|
7
|
+
- 2.0.0-p648
|
8
|
+
- 2.1.9
|
9
|
+
- 2.2.6
|
10
|
+
- 2.3.3
|
11
|
+
- 2.4.0
|
12
|
+
- jruby-9.1.12.0
|
13
|
+
matrix:
|
14
|
+
allow_failures:
|
15
|
+
- rvm: 1.8.7
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
== 3.4.2 ==
|
2
|
+
Silence warning from unused variable when using `ruby -w`. Thanks
|
3
|
+
@sambostock!
|
4
|
+
|
5
|
+
== 3.4.1 ==
|
6
|
+
Prevent remote code execution from user controlled diff file paths. This
|
7
|
+
issue was only present in Windows platforms. Thanks @tehryanx for reporting
|
8
|
+
and testing the fix!
|
9
|
+
|
10
|
+
== 3.4.0 ==
|
11
|
+
Remove space between U diff option and context number. Thanks @tomas!
|
12
|
+
Add option to ignore CRLF diffs in HTML comparisons. Thanks @ptyagi16!
|
13
|
+
|
14
|
+
== 3.3.0 ==
|
15
|
+
Fix diff lines that begin with -- or ++. Thanks @dark-panda!
|
16
|
+
|
17
|
+
== 3.2.1 ==
|
18
|
+
Fix default options on alpine linux. Thanks @evgen!
|
19
|
+
|
1
20
|
== 3.1.0 ==
|
2
21
|
Side by side diffs. Thanks Runar Skaare Tveiten!
|
3
22
|
|
data/CONTRIBUTORS
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -24,11 +24,11 @@ A default format can be set like so:
|
|
24
24
|
Installation
|
25
25
|
------------
|
26
26
|
|
27
|
-
###on Unix
|
27
|
+
### on Unix
|
28
28
|
|
29
29
|
gem install diffy
|
30
30
|
|
31
|
-
###on Windows:
|
31
|
+
### on Windows:
|
32
32
|
|
33
33
|
1. Ensure that you have a working `diff` on your machine and in your search path.
|
34
34
|
|
@@ -149,9 +149,9 @@ all default options such as full diff output are supported. The output format
|
|
149
149
|
may be changed by passing the format with the options hash (see below), and all
|
150
150
|
default formats are supported.
|
151
151
|
|
152
|
-
|
152
|
+
Unlike `Diffy::Diff`, `Diffy::SplitDiff` does not use `#to_s` to output
|
153
153
|
the resulting diff. Instead, two self-explanatory methods are used to output
|
154
|
-
the diff
|
154
|
+
the diff: `#left` and `#right`. Using the earlier example, this is what they
|
155
155
|
look like in action:
|
156
156
|
|
157
157
|
```
|
@@ -213,7 +213,7 @@ You can diff files instead of strings by using the `:source` option.
|
|
213
213
|
### Full Diff Output
|
214
214
|
|
215
215
|
By default Diffy removes the superfluous diff output. This is because its
|
216
|
-
default is to show the complete diff'ed file (`diff -
|
216
|
+
default is to show the complete diff'ed file (`diff -U10000` is the default).
|
217
217
|
|
218
218
|
Diffy does support full output, just use the `:include_diff_info => true`
|
219
219
|
option when initializing:
|
@@ -270,13 +270,22 @@ file).
|
|
270
270
|
### Overriding the command line options passed to diff.
|
271
271
|
|
272
272
|
You can use the `:diff` option to override the command line options that are
|
273
|
-
passed to unix diff. They default to `-
|
273
|
+
passed to unix diff. They default to `-U10000`. This option will noop if
|
274
274
|
combined with the `:context` option.
|
275
275
|
|
276
276
|
>> puts Diffy::Diff.new(" foo\nbar\n", "foo\nbar\n", :diff => "-w")
|
277
277
|
foo
|
278
278
|
bar
|
279
279
|
|
280
|
+
### `:ignore_crlf` when doing HTML compares
|
281
|
+
|
282
|
+
You can make the HTML output ignore the CRLF by passing the `:ignore_crlf` option a truthy value.
|
283
|
+
|
284
|
+
>> puts Diffy::Diff.new(" foo\nbar\n", "foo\r\nbar\r\n", ignore_crlf: true).to_s(:html)
|
285
|
+
"<div class=\"diff\"></div>"
|
286
|
+
|
287
|
+
|
288
|
+
|
280
289
|
Default Diff Options
|
281
290
|
--------------------
|
282
291
|
|
@@ -285,9 +294,9 @@ You can set the default options for new `Diffy::Diff`s using the
|
|
285
294
|
Options passed to `Diffy::Diff.new` will be merged into the default options.
|
286
295
|
|
287
296
|
>> Diffy::Diff.default_options
|
288
|
-
=> {:diff=>"-
|
297
|
+
=> {:diff=>"-U10000", :source=>"strings", :include_diff_info=>false, :include_plus_and_minus_in_html=>false}
|
289
298
|
>> Diffy::Diff.default_options.merge!(:source => 'files')
|
290
|
-
=> {:diff=>"-
|
299
|
+
=> {:diff=>"-U10000", :source=>"files", :include_diff_info=>false, :include_plus_and_minus_in_html=>false}
|
291
300
|
|
292
301
|
|
293
302
|
Custom Formats
|
@@ -315,16 +324,6 @@ deletions, and unchanged in a diff.
|
|
315
324
|
Use `#map`, `#inject`, or any of Enumerable's methods. Go crazy.
|
316
325
|
|
317
326
|
|
318
|
-
Ruby Version Compatibility
|
319
|
-
-------------------------
|
320
|
-
|
321
|
-
Support for Ruby 1.8.6 was dropped beginning at version 2.0 in order to support
|
322
|
-
the chainable enumerators available in 1.8.7 and 1.9.
|
323
|
-
|
324
|
-
If you want to use Diffy and Ruby 1.8.6 then:
|
325
|
-
|
326
|
-
$ gem install diffy -v1.1.0
|
327
|
-
|
328
327
|
Testing
|
329
328
|
------------
|
330
329
|
|
data/Rakefile
CHANGED
data/diffy.gemspec
CHANGED
data/lib/diffy/diff.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Diffy
|
2
2
|
class Diff
|
3
3
|
ORIGINAL_DEFAULT_OPTIONS = {
|
4
|
-
:diff => '-
|
4
|
+
:diff => '-U10000',
|
5
5
|
:source => 'strings',
|
6
6
|
:include_diff_info => false,
|
7
7
|
:include_plus_and_minus_in_html => false,
|
@@ -12,7 +12,7 @@ module Diffy
|
|
12
12
|
class << self
|
13
13
|
attr_writer :default_format
|
14
14
|
def default_format
|
15
|
-
@default_format
|
15
|
+
@default_format ||= :text
|
16
16
|
end
|
17
17
|
|
18
18
|
# default options passed to new Diff objects
|
@@ -23,7 +23,7 @@ module Diffy
|
|
23
23
|
|
24
24
|
end
|
25
25
|
include Enumerable
|
26
|
-
attr_reader :string1, :string2, :options
|
26
|
+
attr_reader :string1, :string2, :options
|
27
27
|
|
28
28
|
# supported options
|
29
29
|
# +:diff+:: A cli options string passed to diff
|
@@ -42,20 +42,14 @@ module Diffy
|
|
42
42
|
|
43
43
|
def diff
|
44
44
|
@diff ||= begin
|
45
|
-
paths = case options[:source]
|
45
|
+
@paths = case options[:source]
|
46
46
|
when 'strings'
|
47
47
|
[tempfile(string1), tempfile(string2)]
|
48
48
|
when 'files'
|
49
49
|
[string1, string2]
|
50
50
|
end
|
51
51
|
|
52
|
-
|
53
|
-
# don't use open3 on windows
|
54
|
-
cmd = sprintf '"%s" %s %s', diff_bin, diff_options.join(' '), paths.map { |s| %("#{s}") }.join(' ')
|
55
|
-
diff = `#{cmd}`
|
56
|
-
else
|
57
|
-
diff = Open3.popen3(diff_bin, *(diff_options + paths)) { |i, o, e| o.read }
|
58
|
-
end
|
52
|
+
diff, _stderr, _process_status = Open3.capture3(diff_bin, *(diff_options + @paths))
|
59
53
|
diff.force_encoding('ASCII-8BIT') if diff.respond_to?(:valid_encoding?) && !diff.valid_encoding?
|
60
54
|
if diff =~ /\A\s*\Z/ && !options[:allow_empty_diff]
|
61
55
|
diff = case options[:source]
|
@@ -67,24 +61,37 @@ module Diffy
|
|
67
61
|
end
|
68
62
|
ensure
|
69
63
|
# unlink the tempfiles explicitly now that the diff is generated
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
64
|
+
if defined? @tempfiles # to avoid Ruby warnings about undefined ins var.
|
65
|
+
Array(@tempfiles).each do |t|
|
66
|
+
begin
|
67
|
+
# check that the path is not nil and file still exists.
|
68
|
+
# REE seems to be very agressive with when it magically removes
|
69
|
+
# tempfiles
|
70
|
+
t.unlink if t.path && File.exist?(t.path)
|
71
|
+
rescue => e
|
72
|
+
warn "#{e.class}: #{e}"
|
73
|
+
warn e.backtrace.join("\n")
|
74
|
+
end
|
79
75
|
end
|
80
76
|
end
|
81
77
|
end
|
82
78
|
|
83
79
|
def each
|
84
80
|
lines = case @options[:include_diff_info]
|
85
|
-
when false
|
86
|
-
|
81
|
+
when false
|
82
|
+
# this "primes" the diff and sets up the paths we'll reference below.
|
83
|
+
diff
|
84
|
+
|
85
|
+
# caching this regexp improves the performance of the loop by a
|
86
|
+
# considerable amount.
|
87
|
+
regexp = /^(--- "?#{@paths[0]}"?|\+\+\+ "?#{@paths[1]}"?|@@|\\\\)/
|
88
|
+
|
89
|
+
diff.split("\n").reject{|x| x =~ regexp }.map {|line| line + "\n" }
|
90
|
+
|
91
|
+
when true
|
92
|
+
diff.split("\n").map {|line| line + "\n" }
|
87
93
|
end
|
94
|
+
|
88
95
|
if block_given?
|
89
96
|
lines.each{|line| yield line}
|
90
97
|
else
|
@@ -161,7 +168,7 @@ module Diffy
|
|
161
168
|
|
162
169
|
# options pass to diff program
|
163
170
|
def diff_options
|
164
|
-
Array(options[:context] ? "-U
|
171
|
+
Array(options[:context] ? "-U#{options[:context]}" : options[:diff])
|
165
172
|
end
|
166
173
|
|
167
174
|
end
|
data/lib/diffy/format.rb
CHANGED
data/lib/diffy/html_formatter.rb
CHANGED
@@ -90,10 +90,14 @@ module Diffy
|
|
90
90
|
|
91
91
|
def split_characters(chunk)
|
92
92
|
chunk.gsub(/^./, '').each_line.map do |line|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
93
|
+
if @options[:ignore_crlf]
|
94
|
+
(line.chomp.split('') + ['\n']).map{|chr| ERB::Util.h(chr) }
|
95
|
+
else
|
96
|
+
chars = line.sub(/([\r\n]$)/, '').split('')
|
97
|
+
# add escaped newlines
|
98
|
+
chars << '\n'
|
99
|
+
chars.map{|chr| ERB::Util.h(chr) }
|
100
|
+
end
|
97
101
|
end.flatten.join("\n") + "\n"
|
98
102
|
end
|
99
103
|
|
data/lib/diffy/version.rb
CHANGED
data/spec/diffy_spec.rb
CHANGED
@@ -115,7 +115,7 @@ describe Diffy::Diff do
|
|
115
115
|
describe "handling temp files" do
|
116
116
|
it "should unlink tempfiles after generating the diff" do
|
117
117
|
before_tmpfiles = Dir.entries(Dir.tmpdir)
|
118
|
-
|
118
|
+
::Diffy::Diff.new("a", "b").to_s
|
119
119
|
after_tmpfiles = Dir.entries(Dir.tmpdir)
|
120
120
|
expect(before_tmpfiles).to match_array(after_tmpfiles)
|
121
121
|
end
|
@@ -503,6 +503,13 @@ baz
|
|
503
503
|
expect(@diff.to_s(:html)).to eq(html)
|
504
504
|
end
|
505
505
|
|
506
|
+
it "should treat unix vs windows newlines as same if option :ignore_crlf" do
|
507
|
+
@diff = Diffy::Diff.new("one\ntwo\nthree\n", "one\r\ntwo\r\nthree\r\n",
|
508
|
+
ignore_crlf: true)
|
509
|
+
empty_diff = "<div class=\"diff\"></div>"
|
510
|
+
expect(@diff.to_s(:html)).to eq(empty_diff)
|
511
|
+
end
|
512
|
+
|
506
513
|
describe 'with lines that include \n' do
|
507
514
|
before do
|
508
515
|
string1 = 'a\nb'"\n"
|
@@ -585,12 +592,36 @@ baz
|
|
585
592
|
line
|
586
593
|
end).to eq([" foo\n", " bar\n", "+baz\n"])
|
587
594
|
end
|
595
|
+
|
596
|
+
it "should handle lines that begin with --" do
|
597
|
+
string1 = "a a\n-- b\nc c\n"
|
598
|
+
string2 = "a a\nb b\nc c\n"
|
599
|
+
|
600
|
+
expect(Diffy::Diff.new(string1, string2).to_s).to eq <<-DIFF
|
601
|
+
a a
|
602
|
+
--- b
|
603
|
+
+b b
|
604
|
+
c c
|
605
|
+
DIFF
|
606
|
+
end
|
607
|
+
|
608
|
+
it "should handle lines that begin with ++" do
|
609
|
+
string1 = "a a\nb b\nc c\n"
|
610
|
+
string2 = "a a\n++ b\nc c\n"
|
611
|
+
|
612
|
+
expect(Diffy::Diff.new(string1, string2).to_s).to eq <<-DIFF
|
613
|
+
a a
|
614
|
+
-b b
|
615
|
+
+++ b
|
616
|
+
c c
|
617
|
+
DIFF
|
618
|
+
end
|
588
619
|
end
|
589
620
|
end
|
590
621
|
|
591
622
|
describe Diffy::SplitDiff do
|
592
623
|
before do
|
593
|
-
::Diffy::Diff.default_options.merge!(:diff => '-
|
624
|
+
::Diffy::Diff.default_options.merge!(:diff => '-U10000')
|
594
625
|
end
|
595
626
|
|
596
627
|
it "should fail with invalid format" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diffy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Goldstein
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
description: Convenient diffing in ruby
|
42
42
|
email:
|
43
43
|
- sgrock@gmail.org
|
@@ -68,7 +68,7 @@ homepage: http://github.com/samg/diffy
|
|
68
68
|
licenses:
|
69
69
|
- MIT
|
70
70
|
metadata: {}
|
71
|
-
post_install_message:
|
71
|
+
post_install_message:
|
72
72
|
rdoc_options: []
|
73
73
|
require_paths:
|
74
74
|
- lib
|
@@ -83,9 +83,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
|
-
|
87
|
-
|
88
|
-
signing_key:
|
86
|
+
rubygems_version: 3.0.6
|
87
|
+
signing_key:
|
89
88
|
specification_version: 4
|
90
89
|
summary: A convenient way to diff string in ruby
|
91
90
|
test_files:
|