diffy 3.2.1 → 3.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8126b4d4207609139dafef922f5ac9079dbe775b
4
- data.tar.gz: 9b7eb9af119aed244cf82e9caa2bc89340ac8f27
2
+ SHA256:
3
+ metadata.gz: b2120d3e1b623e2536ad4bb44454847c1ea2033c96cd83a98bc8ec7179a45f55
4
+ data.tar.gz: 306bc14f06cbacb86496e89290ff4c0c4454358939d694f172d423f20d9357ff
5
5
  SHA512:
6
- metadata.gz: b9a542ef87e8b5a4f7eaba863bb0cc6157d462e478153b3aa68fc0303fbd92367ec8fb8fe5a3ca215023d595164c97c7414355829c809deb511c96c5e614f60b
7
- data.tar.gz: 0cd0450cda92e1c04283fa93122284abd027a9fe9ebffc86348228aa0c37c993781fa5faaf8cbe52e00cba1412f4100006e4873a3ba0bed11b3384dedefc921f
6
+ metadata.gz: 2eaed71c7d28fe17f60eaac94491abdbae0ae40d8596d61e92e4c4436d49ee898393268afc70e3bbaca95aecb9d4d10732bec403eaf949790667bca32cdccbca
7
+ data.tar.gz: ba4d8b43b5110ad6143acaf4ee8b9742198164569d4a006bae4e22aca93ca2904ca3b2f66fe43b004f23aea295453be92120d6752741f3fcf88171427f6d5127
data/CHANGELOG CHANGED
@@ -1,5 +1,18 @@
1
+ == 3.4.1 ==
2
+ Prevent remote code execution from user controlled diff file paths. This
3
+ issue was only present in Windows platforms. Thanks @tehryanx for reporting
4
+ and testing the fix!
5
+
6
+ == 3.4.0 ==
7
+ Remove space between U diff option and context number. Thanks @tomas!
8
+ Add option to ignore CRLF diffs in HTML comparisons. Thanks @ptyagi16!
9
+
10
+ == 3.3.0 ==
11
+ Fix diff lines that begin with -- or ++. Thanks @dark-panda!
12
+
1
13
  == 3.2.1 ==
2
14
  Fix default options on alpine linux. Thanks @evgen!
15
+
3
16
  == 3.1.0 ==
4
17
  Side by side diffs. Thanks Runar Skaare Tveiten!
5
18
 
data/CONTRIBUTORS CHANGED
@@ -12,3 +12,4 @@
12
12
  * Skye Shaw
13
13
  * Abinoam P. Marques Jr.
14
14
  * evgen
15
+ * J Smith @dark-panda
data/README.md CHANGED
@@ -277,6 +277,15 @@ combined with the `:context` option.
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
 
data/lib/diffy/diff.rb CHANGED
@@ -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
- if WINDOWS
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]
@@ -84,9 +78,20 @@ module Diffy
84
78
 
85
79
  def each
86
80
  lines = case @options[:include_diff_info]
87
- when false then diff.split("\n").reject{|x| x =~ /^(---|\+\+\+|@@|\\\\)/ }.map {|line| line + "\n" }
88
- when true then diff.split("\n").map {|line| line + "\n" }
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" }
89
93
  end
94
+
90
95
  if block_given?
91
96
  lines.each{|line| yield line}
92
97
  else
@@ -163,7 +168,7 @@ module Diffy
163
168
 
164
169
  # options pass to diff program
165
170
  def diff_options
166
- Array(options[:context] ? "-U #{options[:context]}" : options[:diff])
171
+ Array(options[:context] ? "-U#{options[:context]}" : options[:diff])
167
172
  end
168
173
 
169
174
  end
@@ -90,10 +90,14 @@ module Diffy
90
90
 
91
91
  def split_characters(chunk)
92
92
  chunk.gsub(/^./, '').each_line.map do |line|
93
- chars = line.sub(/([\r\n]$)/, '').split('')
94
- # add escaped newlines
95
- chars << '\n'
96
- chars.map{|chr| ERB::Util.h(chr) }
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
@@ -1,3 +1,3 @@
1
1
  module Diffy
2
- VERSION = '3.2.1'
2
+ VERSION = '3.4.1'
3
3
  end
data/spec/diffy_spec.rb CHANGED
@@ -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,6 +592,30 @@ 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
 
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.2.1
4
+ version: 3.4.1
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: 2018-05-19 00:00:00.000000000 Z
11
+ date: 2022-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -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
- rubyforge_project:
87
- rubygems_version: 2.6.11
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: