Codebase list ruby-diffy / a7125cc
Update upstream source from tag 'upstream/3.4.2' Update to upstream version '3.4.2' with Debian dir 4cc283d6f9137aebfd0731b272b3785f7c0fa02a Vinay Keshava 1 year, 6 months ago
6 changed file(s) with 40 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
0 == 3.4.2 ==
1 Silence warning from unused variable when using `ruby -w`. Thanks
2 @sambostock!
3
4 == 3.4.1 ==
5 Prevent remote code execution from user controlled diff file paths. This
6 issue was only present in Windows platforms. Thanks @tehryanx for reporting
7 and testing the fix!
8
9 == 3.4.0 ==
10 Remove space between U diff option and context number. Thanks @tomas!
11 Add option to ignore CRLF diffs in HTML comparisons. Thanks @ptyagi16!
12
013 == 3.3.0 ==
114 Fix diff lines that begin with -- or ++. Thanks @dark-panda!
215
276276 foo
277277 bar
278278
279 ### `:ignore_crlf` when doing HTML compares
280
281 You can make the HTML output ignore the CRLF by passing the `:ignore_crlf` option a truthy value.
282
283 >> puts Diffy::Diff.new(" foo\nbar\n", "foo\r\nbar\r\n", ignore_crlf: true).to_s(:html)
284 "<div class=\"diff\"></div>"
285
286
287
279288 Default Diff Options
280289 --------------------
281290
4848 [string1, string2]
4949 end
5050
51 if WINDOWS
52 # don't use open3 on windows
53 cmd = sprintf '"%s" %s %s', diff_bin, diff_options.join(' '), @paths.map { |s| %("#{s}") }.join(' ')
54 diff = `#{cmd}`
55 else
56 diff = Open3.popen3(diff_bin, *(diff_options + @paths)) { |i, o, e| o.read }
57 end
51 diff, _stderr, _process_status = Open3.capture3(diff_bin, *(diff_options + @paths))
5852 diff.force_encoding('ASCII-8BIT') if diff.respond_to?(:valid_encoding?) && !diff.valid_encoding?
5953 if diff =~ /\A\s*\Z/ && !options[:allow_empty_diff]
6054 diff = case options[:source]
173167
174168 # options pass to diff program
175169 def diff_options
176 Array(options[:context] ? "-U #{options[:context]}" : options[:diff])
170 Array(options[:context] ? "-U#{options[:context]}" : options[:diff])
177171 end
178172
179173 end
8989
9090 def split_characters(chunk)
9191 chunk.gsub(/^./, '').each_line.map do |line|
92 chars = line.sub(/([\r\n]$)/, '').split('')
93 # add escaped newlines
94 chars << '\n'
95 chars.map{|chr| ERB::Util.h(chr) }
92 if @options[:ignore_crlf]
93 (line.chomp.split('') + ['\n']).map{|chr| ERB::Util.h(chr) }
94 else
95 chars = line.sub(/([\r\n]$)/, '').split('')
96 # add escaped newlines
97 chars << '\n'
98 chars.map{|chr| ERB::Util.h(chr) }
99 end
96100 end.flatten.join("\n") + "\n"
97101 end
98102
00 module Diffy
1 VERSION = '3.3.0'
1 VERSION = '3.4.2'
22 end
502502 expect(@diff.to_s(:html)).to eq(html)
503503 end
504504
505 it "should treat unix vs windows newlines as same if option :ignore_crlf" do
506 @diff = Diffy::Diff.new("one\ntwo\nthree\n", "one\r\ntwo\r\nthree\r\n",
507 ignore_crlf: true)
508 empty_diff = "<div class=\"diff\"></div>"
509 expect(@diff.to_s(:html)).to eq(empty_diff)
510 end
511
505512 describe 'with lines that include \n' do
506513 before do
507514 string1 = 'a\nb'"\n"