diffy 3.3.0 → 3.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f075ae98773be87371ebe062baf246c8e70187b5
4
- data.tar.gz: b6a761844cffe0e12134fafe2e8163dafc158def
2
+ SHA256:
3
+ metadata.gz: 107dc73001f2e00bccf4b4f89a15ba86d045511f125f33bc8ed8987e239b5079
4
+ data.tar.gz: 0a07b298ff5eec7bcbf83adb0e3fa3c59c122796693d75e18d81d9ccfcb131de
5
5
  SHA512:
6
- metadata.gz: cc19ee7c97c81c4937a4c1c95221a45123f96ba730ea29908fa6c08b77bb17217db5a8bf92fd2463eb4275821ada7201b49448615765508ebf9815d72e81c9b3
7
- data.tar.gz: 0e12bfb8ba4bec36c4c659a9157ef6353c1eed14fbb2b2178111e9573cb1a3aab7047208aa1a53cca83f0e956368197aa671885c90066d8fe4766f5263b49a72
6
+ metadata.gz: 47df78d6118935280b9011a77bb0c888da50af9dfac81dd810ca522cf23ad0099b50411a27e2ca57eac0369cb9fd9d82b97ce56525093002f2845d5d8e2e8121
7
+ data.tar.gz: fca9f15d0cd9cca745caa12f59da048f6bd4c62a572abd9987530ef3acacbdf228c78140c3305f618b86dc57a2a50a25fb0336e325f33afd5261c0a47e28f73c
data/CHANGELOG CHANGED
@@ -1,3 +1,16 @@
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
+
1
14
  == 3.3.0 ==
2
15
  Fix diff lines that begin with -- or ++. Thanks @dark-panda!
3
16
 
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
@@ -49,13 +49,7 @@ module Diffy
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]
@@ -174,7 +168,7 @@ module Diffy
174
168
 
175
169
  # options pass to diff program
176
170
  def diff_options
177
- Array(options[:context] ? "-U #{options[:context]}" : options[:diff])
171
+ Array(options[:context] ? "-U#{options[:context]}" : options[:diff])
178
172
  end
179
173
 
180
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.3.0'
2
+ VERSION = '3.4.2'
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"
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.3.0
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: 2018-12-30 00:00:00.000000000 Z
11
+ date: 2022-06-20 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: