diffy 3.3.0 → 3.4.4
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 +5 -5
- data/.travis.yml +1 -0
- data/CHANGELOG +19 -0
- data/CONTRIBUTORS +1 -0
- data/README.md +9 -0
- data/lib/diffy/diff.rb +2 -8
- data/lib/diffy/html_formatter.rb +9 -10
- data/lib/diffy/version.rb +1 -1
- data/lib/diffy.rb +1 -1
- data/spec/diffy_spec.rb +25 -0
- metadata +6 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 47c21389e70aed2e702069a3dbe38eecc74bbc88f37f2ae9f82f26b8bafdea62
|
|
4
|
+
data.tar.gz: b9ac4fc40b5b9b9ec06da6006295733a3d0c5f20c60ba7d58d8d232e7a10c54d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 14e8e0e6da9b5f34b3e065df2750cd0fc4af9a4523310578032d36fd288f2cca5fa5e3625d4bc8f4a864b4be72f3593c5cfce89dca1159b43274cf3c2501edbc
|
|
7
|
+
data.tar.gz: af3dd707b07f2a03489070bf5ae6d79decac71bf1a6370dfb0326f240d620711d44ff31818fcd8bc030c3bf38dda4a3e1762fe0ad044853b7cf72bef3c8b96d7
|
data/.travis.yml
CHANGED
data/CHANGELOG
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
== 3.4.4 ==
|
|
2
|
+
Fix HTML diff highlighting bug for lines containing '\n'. Thanks @P-SiZK!
|
|
3
|
+
|
|
4
|
+
== 3.4.3 ==
|
|
5
|
+
Require open3 unconditionally on Windows. Thanks @avdv!
|
|
6
|
+
|
|
7
|
+
== 3.4.2 ==
|
|
8
|
+
Silence warning from unused variable when using `ruby -w`. Thanks
|
|
9
|
+
@sambostock!
|
|
10
|
+
|
|
11
|
+
== 3.4.1 ==
|
|
12
|
+
Prevent remote code execution from user controlled diff file paths. This
|
|
13
|
+
issue was only present in Windows platforms. Thanks @tehryanx for reporting
|
|
14
|
+
and testing the fix!
|
|
15
|
+
|
|
16
|
+
== 3.4.0 ==
|
|
17
|
+
Remove space between U diff option and context number. Thanks @tomas!
|
|
18
|
+
Add option to ignore CRLF diffs in HTML comparisons. Thanks @ptyagi16!
|
|
19
|
+
|
|
1
20
|
== 3.3.0 ==
|
|
2
21
|
Fix diff lines that begin with -- or ++. Thanks @dark-panda!
|
|
3
22
|
|
data/CONTRIBUTORS
CHANGED
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
|
-
|
|
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
|
|
171
|
+
Array(options[:context] ? "-U#{options[:context]}" : options[:diff])
|
|
178
172
|
end
|
|
179
173
|
|
|
180
174
|
end
|
data/lib/diffy/html_formatter.rb
CHANGED
|
@@ -90,17 +90,19 @@ 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('').map{|chr| ERB::Util.h(chr) } + ['<LINE_BOUNDARY>']
|
|
95
|
+
else
|
|
96
|
+
chars = line.sub(/([\r\n]$)/, '').split('')
|
|
97
|
+
chars.map{|chr| ERB::Util.h(chr) } + ['<LINE_BOUNDARY>']
|
|
98
|
+
end
|
|
97
99
|
end.flatten.join("\n") + "\n"
|
|
98
100
|
end
|
|
99
101
|
|
|
100
102
|
def reconstruct_characters(line_diff, type)
|
|
101
103
|
enum = line_diff.each_chunk.to_a
|
|
102
104
|
enum.each_with_index.map do |l, i|
|
|
103
|
-
re = /(
|
|
105
|
+
re = /(^|<LINE_BOUNDARY>)#{Regexp.escape(type)}/
|
|
104
106
|
case l
|
|
105
107
|
when re
|
|
106
108
|
highlight(l)
|
|
@@ -109,7 +111,7 @@ module Diffy
|
|
|
109
111
|
highlight(l)
|
|
110
112
|
else
|
|
111
113
|
l.gsub(/^./, '').gsub("\n", '').
|
|
112
|
-
gsub('\r', "\r").gsub('
|
|
114
|
+
gsub('\r', "\r").gsub('<LINE_BOUNDARY>', "\n")
|
|
113
115
|
end
|
|
114
116
|
end
|
|
115
117
|
end.join('').split("\n").map do |l|
|
|
@@ -121,10 +123,7 @@ module Diffy
|
|
|
121
123
|
"<strong>" +
|
|
122
124
|
lines.
|
|
123
125
|
# strip diff tokens (e.g. +,-,etc.)
|
|
124
|
-
gsub(/(
|
|
125
|
-
# mark line boundaries from higher level line diff
|
|
126
|
-
# html is all escaped so using brackets should make this safe.
|
|
127
|
-
gsub('\n', '<LINE_BOUNDARY>').
|
|
126
|
+
gsub(/(^|<LINE_BOUNDARY>)./, '').
|
|
128
127
|
# join characters back by stripping out newlines
|
|
129
128
|
gsub("\n", '').
|
|
130
129
|
# close and reopen strong tags. we don't want inline elements
|
data/lib/diffy/version.rb
CHANGED
data/lib/diffy.rb
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
require 'tempfile'
|
|
2
2
|
require 'erb'
|
|
3
3
|
require 'rbconfig'
|
|
4
|
+
require 'open3'
|
|
4
5
|
|
|
5
6
|
module Diffy
|
|
6
7
|
WINDOWS = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
|
|
7
8
|
end
|
|
8
|
-
require 'open3' unless Diffy::WINDOWS
|
|
9
9
|
require File.join(File.dirname(__FILE__), 'diffy', 'format')
|
|
10
10
|
require File.join(File.dirname(__FILE__), 'diffy', 'html_formatter')
|
|
11
11
|
require File.join(File.dirname(__FILE__), 'diffy', 'diff')
|
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"
|
|
@@ -523,6 +530,24 @@ baz
|
|
|
523
530
|
end
|
|
524
531
|
end
|
|
525
532
|
|
|
533
|
+
describe 'with lines that include \n but not as a diff' do
|
|
534
|
+
before do
|
|
535
|
+
@string1 = 'a\nb'"\n"
|
|
536
|
+
@string2 = 'a\nc'"\n"
|
|
537
|
+
end
|
|
538
|
+
|
|
539
|
+
it "should not leave lines out" do
|
|
540
|
+
expect(Diffy::Diff.new(@string1, @string2).to_s(:html)).to eq <<-DIFF
|
|
541
|
+
<div class="diff">
|
|
542
|
+
<ul>
|
|
543
|
+
<li class="del"><del>a\\n<strong>b</strong></del></li>
|
|
544
|
+
<li class="ins"><ins>a\\n<strong>c</strong></ins></li>
|
|
545
|
+
</ul>
|
|
546
|
+
</div>
|
|
547
|
+
DIFF
|
|
548
|
+
end
|
|
549
|
+
end
|
|
550
|
+
|
|
526
551
|
it "should do highlighting on the last line when there's no trailing newlines" do
|
|
527
552
|
s1 = "foo\nbar\nbang"
|
|
528
553
|
s2 = "foo\nbar\nbangleize"
|
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.4
|
|
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: 2025-06-09 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
|
-
|
|
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:
|