diffy 3.4.3 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4917a9c5ce62dd40fcba1bd26dbe0d43cb864bc17191eb6f1f6d75f0335379b
4
- data.tar.gz: 4ec8d980136421bb271f89c61d50ff72caa02fa8ed650e05004f41d0107bfcd8
3
+ metadata.gz: 47c21389e70aed2e702069a3dbe38eecc74bbc88f37f2ae9f82f26b8bafdea62
4
+ data.tar.gz: b9ac4fc40b5b9b9ec06da6006295733a3d0c5f20c60ba7d58d8d232e7a10c54d
5
5
  SHA512:
6
- metadata.gz: 874f8c29026f342558611b1860a45cd51b4d6f5cee3ce5b139e0d3b03f3e0fb1fcc71fb9581550b5be76ad7c213a78f614fdf1688e3612dfc528ae06788975bb
7
- data.tar.gz: f0e8ac0ec13e20432927bbcaf4f25caadc30d9af763272c85f8f13a3d32473f9fcb5e1e50a6298843daeea6de0cfd18f3a4755536b8e7399fdc4329554881e56
6
+ metadata.gz: 14e8e0e6da9b5f34b3e065df2750cd0fc4af9a4523310578032d36fd288f2cca5fa5e3625d4bc8f4a864b4be72f3593c5cfce89dca1159b43274cf3c2501edbc
7
+ data.tar.gz: af3dd707b07f2a03489070bf5ae6d79decac71bf1a6370dfb0326f240d620711d44ff31818fcd8bc030c3bf38dda4a3e1762fe0ad044853b7cf72bef3c8b96d7
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ == 3.4.4 ==
2
+ Fix HTML diff highlighting bug for lines containing '\n'. Thanks @P-SiZK!
3
+
1
4
  == 3.4.3 ==
2
5
  Require open3 unconditionally on Windows. Thanks @avdv!
3
6
 
data/CONTRIBUTORS CHANGED
@@ -13,3 +13,4 @@
13
13
  * Abinoam P. Marques Jr.
14
14
  * evgen
15
15
  * J Smith @dark-panda
16
+ * @P-SiZK
@@ -91,12 +91,10 @@ module Diffy
91
91
  def split_characters(chunk)
92
92
  chunk.gsub(/^./, '').each_line.map do |line|
93
93
  if @options[:ignore_crlf]
94
- (line.chomp.split('') + ['\n']).map{|chr| ERB::Util.h(chr) }
94
+ line.chomp.split('').map{|chr| ERB::Util.h(chr) } + ['<LINE_BOUNDARY>']
95
95
  else
96
96
  chars = line.sub(/([\r\n]$)/, '').split('')
97
- # add escaped newlines
98
- chars << '\n'
99
- chars.map{|chr| ERB::Util.h(chr) }
97
+ chars.map{|chr| ERB::Util.h(chr) } + ['<LINE_BOUNDARY>']
100
98
  end
101
99
  end.flatten.join("\n") + "\n"
102
100
  end
@@ -104,7 +102,7 @@ module Diffy
104
102
  def reconstruct_characters(line_diff, type)
105
103
  enum = line_diff.each_chunk.to_a
106
104
  enum.each_with_index.map do |l, i|
107
- re = /(^|\\n)#{Regexp.escape(type)}/
105
+ re = /(^|<LINE_BOUNDARY>)#{Regexp.escape(type)}/
108
106
  case l
109
107
  when re
110
108
  highlight(l)
@@ -113,7 +111,7 @@ module Diffy
113
111
  highlight(l)
114
112
  else
115
113
  l.gsub(/^./, '').gsub("\n", '').
116
- gsub('\r', "\r").gsub('\n', "\n")
114
+ gsub('\r', "\r").gsub('<LINE_BOUNDARY>', "\n")
117
115
  end
118
116
  end
119
117
  end.join('').split("\n").map do |l|
@@ -125,10 +123,7 @@ module Diffy
125
123
  "<strong>" +
126
124
  lines.
127
125
  # strip diff tokens (e.g. +,-,etc.)
128
- gsub(/(^|\\n)./, '').
129
- # mark line boundaries from higher level line diff
130
- # html is all escaped so using brackets should make this safe.
131
- gsub('\n', '<LINE_BOUNDARY>').
126
+ gsub(/(^|<LINE_BOUNDARY>)./, '').
132
127
  # join characters back by stripping out newlines
133
128
  gsub("\n", '').
134
129
  # close and reopen strong tags. we don't want inline elements
data/lib/diffy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Diffy
2
- VERSION = '3.4.3'
2
+ VERSION = '3.4.4'
3
3
  end
data/spec/diffy_spec.rb CHANGED
@@ -530,6 +530,24 @@ baz
530
530
  end
531
531
  end
532
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
+
533
551
  it "should do highlighting on the last line when there's no trailing newlines" do
534
552
  s1 = "foo\nbar\nbang"
535
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.3
4
+ version: 3.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Goldstein
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-21 00:00:00.000000000 Z
11
+ date: 2025-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake