diff-lcs 1.5.1 → 1.6.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.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +518 -0
  3. data/CODE_OF_CONDUCT.md +128 -0
  4. data/CONTRIBUTING.md +71 -0
  5. data/CONTRIBUTORS.md +49 -0
  6. data/{License.md → LICENCE.md} +15 -16
  7. data/Manifest.txt +61 -5
  8. data/README.md +92 -0
  9. data/Rakefile +48 -63
  10. data/SECURITY.md +41 -0
  11. data/docs/artistic.txt +1 -1
  12. data/lib/diff/lcs/backports.rb +4 -0
  13. data/lib/diff/lcs/change.rb +3 -3
  14. data/lib/diff/lcs/htmldiff.rb +5 -3
  15. data/lib/diff/lcs/hunk.rb +38 -22
  16. data/lib/diff/lcs/ldiff.rb +65 -49
  17. data/lib/diff/lcs/version.rb +7 -0
  18. data/lib/diff/lcs.rb +12 -11
  19. data/mise.toml +5 -0
  20. data/spec/fixtures/123_x +2 -0
  21. data/spec/fixtures/456_x +2 -0
  22. data/spec/fixtures/empty +0 -0
  23. data/spec/fixtures/file1.bin +0 -0
  24. data/spec/fixtures/file2.bin +0 -0
  25. data/spec/fixtures/four_lines +4 -0
  26. data/spec/fixtures/four_lines_with_missing_new_line +4 -0
  27. data/spec/fixtures/ldiff/diff.missing_new_line1-e +1 -0
  28. data/spec/fixtures/ldiff/diff.missing_new_line1-f +1 -0
  29. data/spec/fixtures/ldiff/diff.missing_new_line2-e +1 -0
  30. data/spec/fixtures/ldiff/diff.missing_new_line2-f +1 -0
  31. data/spec/fixtures/ldiff/error.diff.chef-e +2 -0
  32. data/spec/fixtures/ldiff/error.diff.chef-f +2 -0
  33. data/spec/fixtures/ldiff/error.diff.missing_new_line1-e +1 -0
  34. data/spec/fixtures/ldiff/error.diff.missing_new_line1-f +1 -0
  35. data/spec/fixtures/ldiff/error.diff.missing_new_line2-e +1 -0
  36. data/spec/fixtures/ldiff/error.diff.missing_new_line2-f +1 -0
  37. data/spec/fixtures/ldiff/output.diff.bin1 +0 -0
  38. data/spec/fixtures/ldiff/output.diff.bin1-c +0 -0
  39. data/spec/fixtures/ldiff/output.diff.bin1-e +0 -0
  40. data/spec/fixtures/ldiff/output.diff.bin1-f +0 -0
  41. data/spec/fixtures/ldiff/output.diff.bin1-u +0 -0
  42. data/spec/fixtures/ldiff/output.diff.bin2 +1 -0
  43. data/spec/fixtures/ldiff/output.diff.bin2-c +1 -0
  44. data/spec/fixtures/ldiff/output.diff.bin2-e +1 -0
  45. data/spec/fixtures/ldiff/output.diff.bin2-f +1 -0
  46. data/spec/fixtures/ldiff/output.diff.bin2-u +1 -0
  47. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines +5 -0
  48. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-c +9 -0
  49. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-e +6 -0
  50. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-f +6 -0
  51. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-u +7 -0
  52. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty +5 -0
  53. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-c +9 -0
  54. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-e +1 -0
  55. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-f +1 -0
  56. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-u +7 -0
  57. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context +4 -0
  58. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-c +9 -0
  59. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-e +3 -0
  60. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-f +3 -0
  61. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-u +6 -0
  62. data/spec/fixtures/ldiff/output.diff.missing_new_line1 +5 -0
  63. data/spec/fixtures/ldiff/output.diff.missing_new_line1-c +14 -0
  64. data/spec/fixtures/ldiff/output.diff.missing_new_line1-e +0 -0
  65. data/spec/fixtures/ldiff/output.diff.missing_new_line1-f +0 -0
  66. data/spec/fixtures/ldiff/output.diff.missing_new_line1-u +9 -0
  67. data/spec/fixtures/ldiff/output.diff.missing_new_line2 +5 -0
  68. data/spec/fixtures/ldiff/output.diff.missing_new_line2-c +14 -0
  69. data/spec/fixtures/ldiff/output.diff.missing_new_line2-e +0 -0
  70. data/spec/fixtures/ldiff/output.diff.missing_new_line2-f +0 -0
  71. data/spec/fixtures/ldiff/output.diff.missing_new_line2-u +9 -0
  72. data/spec/hunk_spec.rb +1 -1
  73. data/spec/issues_spec.rb +32 -32
  74. data/spec/ldiff_spec.rb +21 -10
  75. data/spec/patch_spec.rb +1 -1
  76. data/spec/spec_helper.rb +93 -93
  77. metadata +87 -65
  78. data/Code-of-Conduct.md +0 -74
  79. data/Contributing.md +0 -121
  80. data/History.md +0 -431
  81. data/README.rdoc +0 -84
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,71 @@
1
+ # Contributing
2
+
3
+ Contribution to diff-lcs is encouraged in any form: a bug report, a feature
4
+ request, or code contributions. There are a few DOs and DON'Ts for
5
+ contributions.
6
+
7
+ - DO:
8
+
9
+ - Keep the coding style that already exists for any updated Ruby code (support
10
+ or otherwise). I use [Standard Ruby][standardrb] for linting and formatting.
11
+
12
+ - Use thoughtfully-named topic branches for contributions. Rebase your commits
13
+ into logical chunks as necessary.
14
+
15
+ - Use [quality commit messages][qcm].
16
+
17
+ - Add your name or GitHub handle to `CONTRIBUTORS.md` and a record in the
18
+ `CHANGELOG.md` as a separate commit from your main change. (Follow the style
19
+ in the `CHANGELOG.md` and provide a link to your PR.)
20
+
21
+ - Add or update tests as appropriate for your change. The test suite is
22
+ written in [RSpec][rspec].
23
+
24
+ - Add or update documentation as appropriate for your change. The
25
+ documentation is RDoc; diff-lcs does not use extensions that may be present
26
+ in alternative documentation generators.
27
+
28
+ - DO NOT:
29
+
30
+ - Modify `VERSION` in `lib/diff/lcs/version.rb`. When your patch is accepted
31
+ and a release is made, the version will be updated at that point.
32
+
33
+ - Modify `diff-lcs.gemspec`; it is a generated file. (You _may_ use
34
+ `rake gemspec` to regenerate it if your change involves metadata related to
35
+ gem itself).
36
+
37
+ - Modify the `Gemfile`.
38
+
39
+ ## Test Dependencies
40
+
41
+ diff-lcs uses Ryan Davis's [Hoe][Hoe] to manage the release process, and it adds
42
+ a number of rake tasks. You will mostly be interested in `rake`, which runs
43
+ tests in the same way that `rake spec` does.
44
+
45
+ To assist with the installation of the development dependencies for diff-lcs, I
46
+ have provided a Gemfile pointing to the (generated) `diff-lcs.gemspec` file.
47
+ `minitar.gemspec` file. This will permit you to use `bundle install` to install
48
+ the dependencies.
49
+
50
+ You can run tests with code coverage analysis by running `rake spec:coverage`.
51
+
52
+ ## Workflow
53
+
54
+ Here's the most direct way to get your work merged into the project:
55
+
56
+ - Fork the project.
57
+ - Clone your fork (`git clone git://github.com/<username>/diff-lcs.git`).
58
+ - Create a topic branch to contain your change
59
+ (`git checkout -b my_awesome_feature`).
60
+ - Hack away, add tests. Not necessarily in that order.
61
+ - Make sure everything still passes by running `rake`.
62
+ - If necessary, rebase your commits into logical chunks, without errors.
63
+ - Push the branch up (`git push origin my_awesome_feature`).
64
+ - Create a pull request against halostatue/diff-lcs and describe what your
65
+ change does and the why you think it should be merged.
66
+
67
+ [hoe]: https://github.com/seattlerb/hoe
68
+ [qcm]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
69
+ [release-gem]: https://github.com/rubygems/release-gem
70
+ [rspec]: http://rspec.info/documentation/
71
+ [standardrb]: https://github.com/standardrb/standard
data/CONTRIBUTORS.md ADDED
@@ -0,0 +1,49 @@
1
+ # Contributors
2
+
3
+ - Austin Ziegler (@halostatue) created diff-lcs.
4
+
5
+ Thanks to everyone else who has contributed to diff-lcs over the years:
6
+
7
+ - @ginriki
8
+ - @joshbronson
9
+ - @kevinmook
10
+ - @mckaz
11
+ - Akinori Musha
12
+ - Artem Ignatyev
13
+ - Brandon Fish
14
+ - Baptiste Courtois (@annih)
15
+ - Camille Drapier
16
+ - Cédric Boutillier
17
+ - @earlopain
18
+ - Gregg Kellogg
19
+ - Jagdeep Singh
20
+ - Jason Gladish
21
+ - Jon Rowe
22
+ - Josef Strzibny
23
+ - Josep (@apuratepp)
24
+ - Josh Bronson
25
+ - Jun Aruga
26
+ - Justin Steele
27
+ - Kenichi Kamiya
28
+ - Kensuke Nagae
29
+ - Kevin Ansfield
30
+ - Koichi Ito
31
+ - Mark Friedgan
32
+ - Masato Nakamura
33
+ - Mark Young
34
+ - Michael Granger
35
+ - Myron Marston
36
+ - Nicolas Leger
37
+ - Oleg Orlov
38
+ - Patrick Linnane
39
+ - Paul Kunysch
40
+ - Pete Higgins
41
+ - Peter Goldstein
42
+ - Peter Wagenet
43
+ - Philippe Lafoucrière
44
+ - Ryan Lovelett
45
+ - Scott Steele
46
+ - Simon Courtois
47
+ - Tien (@tiendo1011)
48
+ - Tomas Jura
49
+ - Vít Ondruch
@@ -1,15 +1,15 @@
1
- # License
1
+ # Licence
2
2
 
3
3
  This software is available under three licenses: the GNU GPL version 2 (or at
4
4
  your option, a later version), the Perl Artistic license, or the MIT license.
5
5
  Note that my preference for licensing is the MIT license, but Algorithm::Diff
6
- was dually originally licensed with the Perl Artistic and the GNU GPL ("the
7
- same terms as Perl itself") and given that the Ruby implementation originally
8
- hewed pretty closely to the Perl version, I must maintain the additional
9
- licensing terms.
6
+ was dually originally licensed with the Perl Artistic and the GNU GPL ("the same
7
+ terms as Perl itself") and given that the Ruby implementation originally hewed
8
+ pretty closely to the Perl version, I must maintain the additional licensing
9
+ terms.
10
10
 
11
- * Copyright 2004–2013 Austin Ziegler.
12
- * Adapted from Algorithm::Diff (Perl) by Ned Konz and a Smalltalk version by
11
+ - Copyright 2004–2025 Austin Ziegler and contributors.
12
+ - Adapted from Algorithm::Diff (Perl) by Ned Konz and a Smalltalk version by
13
13
  Mario I. Wolczko.
14
14
 
15
15
  ## MIT License
@@ -17,20 +17,19 @@ licensing terms.
17
17
  Permission is hereby granted, free of charge, to any person obtaining a copy of
18
18
  this software and associated documentation files (the "Software"), to deal in
19
19
  the Software without restriction, including without limitation the rights to
20
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
21
- of the Software, and to permit persons to whom the Software is furnished to do
22
- so, subject to the following conditions:
20
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
21
+ the Software, and to permit persons to whom the Software is furnished to do so,
22
+ subject to the following conditions:
23
23
 
24
24
  The above copyright notice and this permission notice shall be included in all
25
25
  copies or substantial portions of the Software.
26
26
 
27
27
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
- SOFTWARE.
28
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
29
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
30
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
31
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34
33
 
35
34
  ## Perl Artistic License
36
35
 
data/Manifest.txt CHANGED
@@ -1,11 +1,13 @@
1
1
  .rspec
2
- Code-of-Conduct.md
3
- Contributing.md
4
- History.md
5
- License.md
2
+ CHANGELOG.md
3
+ CODE_OF_CONDUCT.md
4
+ CONTRIBUTING.md
5
+ CONTRIBUTORS.md
6
+ LICENCE.md
6
7
  Manifest.txt
7
- README.rdoc
8
+ README.md
8
9
  Rakefile
10
+ SECURITY.md
9
11
  bin/htmldiff
10
12
  bin/ldiff
11
13
  docs/COPYING.txt
@@ -22,17 +24,46 @@ lib/diff/lcs/hunk.rb
22
24
  lib/diff/lcs/internals.rb
23
25
  lib/diff/lcs/ldiff.rb
24
26
  lib/diff/lcs/string.rb
27
+ lib/diff/lcs/version.rb
28
+ mise.toml
25
29
  spec/change_spec.rb
26
30
  spec/diff_spec.rb
31
+ spec/fixtures/123_x
32
+ spec/fixtures/456_x
27
33
  spec/fixtures/aX
28
34
  spec/fixtures/bXaX
29
35
  spec/fixtures/ds1.csv
30
36
  spec/fixtures/ds2.csv
37
+ spec/fixtures/empty
38
+ spec/fixtures/file1.bin
39
+ spec/fixtures/file2.bin
40
+ spec/fixtures/four_lines
41
+ spec/fixtures/four_lines_with_missing_new_line
42
+ spec/fixtures/ldiff/diff.missing_new_line1-e
43
+ spec/fixtures/ldiff/diff.missing_new_line1-f
44
+ spec/fixtures/ldiff/diff.missing_new_line2-e
45
+ spec/fixtures/ldiff/diff.missing_new_line2-f
46
+ spec/fixtures/ldiff/error.diff.chef-e
47
+ spec/fixtures/ldiff/error.diff.chef-f
48
+ spec/fixtures/ldiff/error.diff.missing_new_line1-e
49
+ spec/fixtures/ldiff/error.diff.missing_new_line1-f
50
+ spec/fixtures/ldiff/error.diff.missing_new_line2-e
51
+ spec/fixtures/ldiff/error.diff.missing_new_line2-f
31
52
  spec/fixtures/ldiff/output.diff
32
53
  spec/fixtures/ldiff/output.diff-c
33
54
  spec/fixtures/ldiff/output.diff-e
34
55
  spec/fixtures/ldiff/output.diff-f
35
56
  spec/fixtures/ldiff/output.diff-u
57
+ spec/fixtures/ldiff/output.diff.bin1
58
+ spec/fixtures/ldiff/output.diff.bin1-c
59
+ spec/fixtures/ldiff/output.diff.bin1-e
60
+ spec/fixtures/ldiff/output.diff.bin1-f
61
+ spec/fixtures/ldiff/output.diff.bin1-u
62
+ spec/fixtures/ldiff/output.diff.bin2
63
+ spec/fixtures/ldiff/output.diff.bin2-c
64
+ spec/fixtures/ldiff/output.diff.bin2-e
65
+ spec/fixtures/ldiff/output.diff.bin2-f
66
+ spec/fixtures/ldiff/output.diff.bin2-u
36
67
  spec/fixtures/ldiff/output.diff.chef
37
68
  spec/fixtures/ldiff/output.diff.chef-c
38
69
  spec/fixtures/ldiff/output.diff.chef-e
@@ -44,6 +75,31 @@ spec/fixtures/ldiff/output.diff.chef2-d
44
75
  spec/fixtures/ldiff/output.diff.chef2-e
45
76
  spec/fixtures/ldiff/output.diff.chef2-f
46
77
  spec/fixtures/ldiff/output.diff.chef2-u
78
+ spec/fixtures/ldiff/output.diff.empty.vs.four_lines
79
+ spec/fixtures/ldiff/output.diff.empty.vs.four_lines-c
80
+ spec/fixtures/ldiff/output.diff.empty.vs.four_lines-e
81
+ spec/fixtures/ldiff/output.diff.empty.vs.four_lines-f
82
+ spec/fixtures/ldiff/output.diff.empty.vs.four_lines-u
83
+ spec/fixtures/ldiff/output.diff.four_lines.vs.empty
84
+ spec/fixtures/ldiff/output.diff.four_lines.vs.empty-c
85
+ spec/fixtures/ldiff/output.diff.four_lines.vs.empty-e
86
+ spec/fixtures/ldiff/output.diff.four_lines.vs.empty-f
87
+ spec/fixtures/ldiff/output.diff.four_lines.vs.empty-u
88
+ spec/fixtures/ldiff/output.diff.issue95_trailing_context
89
+ spec/fixtures/ldiff/output.diff.issue95_trailing_context-c
90
+ spec/fixtures/ldiff/output.diff.issue95_trailing_context-e
91
+ spec/fixtures/ldiff/output.diff.issue95_trailing_context-f
92
+ spec/fixtures/ldiff/output.diff.issue95_trailing_context-u
93
+ spec/fixtures/ldiff/output.diff.missing_new_line1
94
+ spec/fixtures/ldiff/output.diff.missing_new_line1-c
95
+ spec/fixtures/ldiff/output.diff.missing_new_line1-e
96
+ spec/fixtures/ldiff/output.diff.missing_new_line1-f
97
+ spec/fixtures/ldiff/output.diff.missing_new_line1-u
98
+ spec/fixtures/ldiff/output.diff.missing_new_line2
99
+ spec/fixtures/ldiff/output.diff.missing_new_line2-c
100
+ spec/fixtures/ldiff/output.diff.missing_new_line2-e
101
+ spec/fixtures/ldiff/output.diff.missing_new_line2-f
102
+ spec/fixtures/ldiff/output.diff.missing_new_line2-u
47
103
  spec/fixtures/new-chef
48
104
  spec/fixtures/new-chef2
49
105
  spec/fixtures/old-chef
data/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # Diff::LCS
2
+
3
+ - home :: https://github.com/halostatue/diff-lcs
4
+ - changelog :: https://github.com/halostatue/diff-lcs/blob/main/CHANGELOG.md
5
+ - code :: https://github.com/halostatue/diff-lcs
6
+ - bugs :: https://github.com/halostatue/diff-lcs/issues
7
+ - rdoc :: http://rubydoc.info/github/halostatue/diff-lcs
8
+
9
+ <a href="https://github.com/halostatue/diff-lcs/actions">
10
+ <img src="https://github.com/halostatue/diff-lcs/workflows/CI/badge.svg" />
11
+ </a>
12
+
13
+ ## Description
14
+
15
+ Diff::LCS computes the difference between two Enumerable sequences using the
16
+ McIlroy-Hunt longest common subsequence (LCS) algorithm. It includes utilities
17
+ to create a simple HTML diff output format and a standard diff-like tool.
18
+
19
+ This is release 1.6.1, providing a simple extension that allows for
20
+ Diff::LCS::Change objects to be treated implicitly as arrays and fixes a number
21
+ of formatting issues.
22
+
23
+ Ruby versions below 2.5 are soft-deprecated, which means that older versions are
24
+ no longer part of the CI test suite. If any changes have been introduced that
25
+ break those versions, bug reports and patches will be accepted, but it will be
26
+ up to the reporter to verify any fixes prior to release. The next major release
27
+ will completely break compatibility.
28
+
29
+ ## Synopsis
30
+
31
+ Using this module is quite simple. By default, Diff::LCS does not extend objects
32
+ with the Diff::LCS interface, but will be called as if it were a function:
33
+
34
+ ```ruby
35
+ require 'diff/lcs'
36
+
37
+ seq1 = %w(a b c e h j l m n p)
38
+ seq2 = %w(b c d e f j k l m r s t)
39
+
40
+ lcs = Diff::LCS.LCS(seq1, seq2)
41
+ diffs = Diff::LCS.diff(seq1, seq2)
42
+ sdiff = Diff::LCS.sdiff(seq1, seq2)
43
+ seq = Diff::LCS.traverse_sequences(seq1, seq2, callback_obj)
44
+ bal = Diff::LCS.traverse_balanced(seq1, seq2, callback_obj)
45
+ seq2 == Diff::LCS.patch!(seq1, diffs)
46
+ seq1 == Diff::LCS.unpatch!(seq2, diffs)
47
+ seq2 == Diff::LCS.patch!(seq1, sdiff)
48
+ seq1 == Diff::LCS.unpatch!(seq2, sdiff)
49
+ ```
50
+
51
+ Objects can be extended with Diff::LCS:
52
+
53
+ ```ruby
54
+ seq1.extend(Diff::LCS)
55
+ lcs = seq1.lcs(seq2)
56
+ diffs = seq1.diff(seq2)
57
+ sdiff = seq1.sdiff(seq2)
58
+ seq = seq1.traverse_sequences(seq2, callback_obj)
59
+ bal = seq1.traverse_balanced(seq2, callback_obj)
60
+ seq2 == seq1.patch!(diffs)
61
+ seq1 == seq2.unpatch!(diffs)
62
+ seq2 == seq1.patch!(sdiff)
63
+ seq1 == seq2.unpatch!(sdiff)
64
+ ```
65
+
66
+ By requiring 'diff/lcs/array' or 'diff/lcs/string', Array or String will be
67
+ extended for use this way.
68
+
69
+ Note that Diff::LCS requires a sequenced enumerable container, which means that
70
+ the order of enumeration is both predictable and consistent for the same set of
71
+ data. While it is theoretically possible to generate a diff for an unordered
72
+ hash, it will only be meaningful if the enumeration of the hashes is consistent.
73
+ In general, this will mean that containers that behave like String or Array will
74
+ perform best.
75
+
76
+ ## History
77
+
78
+ Diff::LCS is a port of Perl's Algorithm::Diff that uses the McIlroy-Hunt longest
79
+ common subsequence (LCS) algorithm to compute intelligent differences between
80
+ two sequenced enumerable containers. The implementation is based on Mario I.
81
+ Wolczko's [Smalltalk version 1.2][smalltalk] (1993) and Ned Konz's Perl version
82
+ [Algorithm::Diff 1.15][perl]. `Diff::LCS#sdiff` and
83
+ `Diff::LCS#traverse_balanced` were originally written for the Perl version by
84
+ Mike Schilli.
85
+
86
+ The algorithm is described in <em>A Fast Algorithm for Computing Longest Common
87
+ Subsequences</em>, CACM, vol.20, no.5, pp.350-353, May 1977, with a few minor
88
+ improvements to improve the speed. A simplified description of the algorithm,
89
+ originally written for the Perl version, was written by Mark-Jason Dominus.
90
+
91
+ [smalltalk]: ftp://st.cs.uiuc.edu/pub/Smalltalk/MANCHESTER/manchester/4.0/diff.st
92
+ [perl]: http://search.cpan.org/~nedkonz/Algorithm-Diff-1.15/
data/Rakefile CHANGED
@@ -1,49 +1,20 @@
1
- # frozen_string_literal: true
2
-
3
1
  require "rubygems"
4
2
  require "rspec"
5
3
  require "rspec/core/rake_task"
6
4
  require "hoe"
5
+ require "rake/clean"
7
6
 
8
- # This is required until https://github.com/seattlerb/hoe/issues/112 is fixed
9
- class Hoe
10
- def with_config
11
- config = Hoe::DEFAULT_CONFIG
12
-
13
- rc = File.expand_path("~/.hoerc")
14
- homeconfig = load_config(rc)
15
- config = config.merge(homeconfig)
16
-
17
- localconfig = load_config(File.expand_path(File.join(Dir.pwd, ".hoerc")))
18
- config = config.merge(localconfig)
19
-
20
- yield config, rc
21
- end
22
-
23
- def load_config(name)
24
- File.exist?(name) ? safe_load_yaml(name) : {}
25
- end
26
-
27
- def safe_load_yaml(name)
28
- return safe_load_yaml_file(name) if YAML.respond_to?(:safe_load_file)
29
-
30
- data = IO.binread(name)
31
- YAML.safe_load(data, permitted_classes: [Regexp])
32
- rescue
33
- YAML.safe_load(data, [Regexp])
34
- end
7
+ MAINTENANCE = ENV["MAINTENANCE"] == "true"
8
+ BUILD_DOCS = MAINTENANCE || ENV["DOCS"] == "true"
9
+ TRUSTED_RELEASE = ENV["rubygems_release_gem"] == "true"
35
10
 
36
- def safe_load_yaml_file(name)
37
- YAML.safe_load_file(name, permitted_classes: [Regexp])
38
- rescue
39
- YAML.safe_load_file(name, [Regexp])
40
- end
41
- end
11
+ Hoe.plugin :halostatue
12
+ Hoe.plugin :rubygems
42
13
 
43
- Hoe.plugin :bundler
44
- Hoe.plugin :doofus
45
- Hoe.plugin :gemspec2
46
- Hoe.plugin :git
14
+ Hoe.plugins.delete :debug
15
+ Hoe.plugins.delete :newb
16
+ Hoe.plugins.delete :signing
17
+ Hoe.plugins.delete :publish unless BUILD_DOCS
47
18
 
48
19
  if RUBY_VERSION < "1.9"
49
20
  class Array # :nodoc:
@@ -70,30 +41,45 @@ end
70
41
  _spec = Hoe.spec "diff-lcs" do
71
42
  developer("Austin Ziegler", "halostatue@gmail.com")
72
43
 
44
+ self.trusted_release = TRUSTED_RELEASE
45
+
73
46
  require_ruby_version ">= 1.8"
74
47
 
75
- self.history_file = "History.md"
76
- self.readme_file = "README.rdoc"
77
- self.licenses = ["MIT", "Artistic-2.0", "GPL-2.0-or-later"]
48
+ self.history_file = "CHANGELOG.md"
49
+ self.readme_file = "README.md"
50
+ self.licenses = ["MIT", "Artistic-1.0-Perl", "GPL-2.0-or-later"]
78
51
 
79
- spec_extras[:metadata] = ->(val) { val["rubygems_mfa_required"] = "true" }
52
+ spec_extras[:metadata] = ->(val) {
53
+ val["rubygems_mfa_required"] = "true"
54
+ }
80
55
 
81
- extra_dev_deps << ["hoe", ">= 3.0", "< 5"]
82
- extra_dev_deps << ["hoe-doofus", "~> 1.0"]
83
- extra_dev_deps << ["hoe-gemspec2", "~> 1.1"]
84
- extra_dev_deps << ["hoe-git2", "~> 1.7"]
56
+ extra_dev_deps << ["hoe", "~> 4.0"]
57
+ extra_dev_deps << ["hoe-halostatue", "~> 2.0"]
85
58
  extra_dev_deps << ["hoe-rubygems", "~> 1.0"]
86
59
  extra_dev_deps << ["rspec", ">= 2.0", "< 4"]
87
60
  extra_dev_deps << ["rake", ">= 10.0", "< 14"]
88
61
  extra_dev_deps << ["rdoc", ">= 6.3.1", "< 7"]
89
62
  end
90
63
 
64
+ if BUILD_DOCS
65
+ rake_tasks = Rake.application.instance_variable_get(:@tasks)
66
+ tasks = ["publish_docs", "publish_on_announce", "debug_email", "post_blog", "announce"]
67
+ tasks.each do |task|
68
+ rake_tasks.delete(task)
69
+ end
70
+ end
71
+
91
72
  desc "Run all specifications"
92
73
  RSpec::Core::RakeTask.new(:spec) do |t|
93
74
  rspec_dirs = %w[spec lib].join(":")
94
75
  t.rspec_opts = ["-I#{rspec_dirs}"]
95
76
  end
96
77
 
78
+ task :version do
79
+ require "diff/lcs/version"
80
+ puts Diff::LCS::VERSION
81
+ end
82
+
97
83
  Rake::Task["spec"].actions.uniq! { |a| a.source_location }
98
84
 
99
85
  # standard:disable Style/HashSyntax
@@ -101,30 +87,29 @@ task :default => :spec unless Rake::Task["default"].prereqs.include?("spec")
101
87
  task :test => :spec unless Rake::Task["test"].prereqs.include?("spec")
102
88
  # standard:enable Style/HashSyntax
103
89
 
104
- if RUBY_VERSION >= "2.0" && RUBY_ENGINE == "ruby"
90
+ if RUBY_VERSION >= "3.0" && RUBY_ENGINE == "ruby"
105
91
  namespace :spec do
106
92
  desc "Runs test coverage. Only works Ruby 2.0+ and assumes 'simplecov' is installed."
107
93
  task :coverage do
108
- ENV["COVERAGE"] = "yes"
94
+ ENV["COVERAGE"] = "true"
109
95
  Rake::Task["spec"].execute
110
96
  end
111
97
  end
112
98
  end
113
99
 
114
- task :ruby18 do
115
- # standard:disable Layout/HeredocIndentation
116
- puts <<-MESSAGE
117
- You are starting a barebones Ruby 1.8 docker environment. You will need to
118
- do the following:
100
+ if MAINTENANCE
101
+ task ruby18: :package do
102
+ require "diff/lcs/version"
103
+ # standard:disable Layout/HeredocIndentation
104
+ puts <<-MESSAGE
105
+ You are starting a barebones Ruby 1.8 docker environment for testing.
106
+ A snapshot package has been built, so install it with:
119
107
 
120
- - mv Gemfile.lock{,.v2}
121
- - gem install bundler --version 1.17.2 --no-ri --no-rdoc
122
- - ruby -S bundle
123
- - rake
108
+ cd diff-lcs
109
+ gem install pkg/diff-lcs-#{Diff::LCS::VERSION}
124
110
 
125
- Don't forget to restore your Gemfile.lock after testing.
126
-
127
- MESSAGE
128
- # standard:enable Layout/HeredocIndentation
129
- sh "docker run -it --rm -v #{Dir.pwd}:/root/diff-lcs bellbind/docker-ruby18-rails2 bash -l"
111
+ MESSAGE
112
+ # standard:enable Layout/HeredocIndentation
113
+ sh "docker run -it --rm -v #{Dir.pwd}:/root/diff-lcs bellbind/docker-ruby18-rails2 bash -l"
114
+ end
130
115
  end
data/SECURITY.md ADDED
@@ -0,0 +1,41 @@
1
+ # diff-lcs Security
2
+
3
+ ## Supported Versions
4
+
5
+ Security reports are accepted for the most recent major release and the previous
6
+ version for a limited time after the initial major release version. After a
7
+ major release, the previous version will receive full support for six months and
8
+ security support for an additional six months (for a total of twelve months).
9
+
10
+ Because diff-lcs 1.x supports a wide range of Ruby versions, security reports
11
+ will only be accepted when they can be demonstrated on Ruby 3.1 or higher.
12
+
13
+ > [!information]
14
+ >
15
+ > There will be a diff-lcs 2.0 released in 2025 which narrows support to modern
16
+ > versions of Ruby only.
17
+ >
18
+ > | Release Date | Support Ends | Security Support Ends |
19
+ > | ------------ | ------------ | --------------------- |
20
+ > | 2025 | +6 months | +12 months |
21
+ >
22
+ > If the 2.0.0 release happens on 2025-07-01, regular support for diff-lcs 1.x
23
+ > will end on 2026-12-31 and security support for diff-lcs 1.x will end on
24
+ > 2026-06-30.
25
+
26
+ ## Reporting a Vulnerability
27
+
28
+ By preference, use the [Tidelift security contact][tidelift]. Tidelift will
29
+ coordinate the fix and disclosure.
30
+
31
+ Alternatively, Send an email to [diff-lcs@halostatue.ca][email] with the text
32
+ `Diff::LCS` in the subject. Emails sent to this address should be encrypted
33
+ using [age][age] with the following public key:
34
+
35
+ ```
36
+ age1fc6ngxmn02m62fej5cl30lrvwmxn4k3q2atqu53aatekmnqfwumqj4g93w
37
+ ```
38
+
39
+ [tidelift]: https://tidelift.com/security
40
+ [email]: mailto:diff-lcs@halostatue.ca
41
+ [age]: https://github.com/FiloSottile/age
data/docs/artistic.txt CHANGED
@@ -122,6 +122,6 @@ products derived from this software without specific prior written permission.
122
122
 
123
123
  10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
124
124
  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
125
- WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
125
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
126
126
 
127
127
  The End
@@ -5,5 +5,9 @@ unless 0.respond_to?(:positive?)
5
5
  def positive?
6
6
  self > 0
7
7
  end
8
+
9
+ def negative?
10
+ self < 0
11
+ end
8
12
  end
9
13
  end
@@ -4,7 +4,7 @@
4
4
  # addition of an element from either the old or the new sequenced
5
5
  # enumerable.
6
6
  class Diff::LCS::Change
7
- IntClass = 1.class # Fixnum is deprecated in Ruby 2.4 # rubocop:disable Naming/ConstantName
7
+ IntClass = 1.class # Fixnum is deprecated in Ruby 2.4 # standard:disable Naming/ConstantName
8
8
 
9
9
  # The only actions valid for changes are '+' (add), '-' (delete), '='
10
10
  # (no change), '!' (changed), '<' (tail changes from first sequence), or
@@ -45,9 +45,9 @@ class Diff::LCS::Change
45
45
  arr = arr.flatten(1)
46
46
  case arr.size
47
47
  when 5
48
- Diff::LCS::ContextChange.new(*(arr[0...5]))
48
+ Diff::LCS::ContextChange.new(*arr[0...5])
49
49
  when 3
50
- Diff::LCS::Change.new(*(arr[0...3]))
50
+ Diff::LCS::Change.new(*arr[0...3])
51
51
  else
52
52
  fail "Invalid change array format provided."
53
53
  end
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "cgi"
3
+ require "erb"
4
4
 
5
5
  # Produce a simple HTML diff view.
6
6
  class Diff::LCS::HTMLDiff
7
7
  class << self
8
+ # standard:disable ThreadSafety/ClassAndModuleAttributes
8
9
  attr_accessor :can_expand_tabs # :nodoc:
10
+ # standard:enable ThreadSafety/ClassAndModuleAttributes
9
11
  end
10
12
  self.can_expand_tabs = true
11
13
 
@@ -124,8 +126,8 @@ h1 { margin-left: 2em; }
124
126
  @right.map! { |line| formatter.expand(line.chomp) }
125
127
  end
126
128
 
127
- @left.map! { |line| CGI.escapeHTML(line.chomp) }
128
- @right.map! { |line| CGI.escapeHTML(line.chomp) }
129
+ @left.map! { |line| ERB::Util.html_escape(line.chomp) }
130
+ @right.map! { |line| ERB::Util.html_escape(line.chomp) }
129
131
 
130
132
  # standard:disable Layout/HeredocIndentation
131
133
  @options[:output] << <<-OUTPUT