Skip to content

Commit

Permalink
[FIXED] Longest common paths returning incorrect single directory [#1…
Browse files Browse the repository at this point in the history
…69276334]
  • Loading branch information
xtreme-shane-lattanzio committed Dec 9, 2019
1 parent 370a002 commit f1d5423
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/license_finder/shared_helpers/common_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def self.longest_common_paths(paths)

longest_common_path = potential_path
end
common_paths << longest_common_path

longest_common_path = full_paths if longest_common_path.split('/').length == 1
(common_paths << longest_common_path).flatten!
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/license_finder/shared_helpers/common_path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
let(:gvt_output_without_common_paths) do
%w[cloud.google.com/go/bigquery/adsf cloud.google.com/go/civil cloud.aws.com/go/metadata]
end
let(:gvt_output_with_github_common_path) do
%w[github.com/cloud.google.com/go/bigquery github.com/stuff/cloud.google.com/go/civil github.com/things/cloud.google.com/go/compute/metadata]
end

it 'only shows the entry with common base path once' do
paths = CommonPathHelper.longest_common_paths gvt_output_with_common_paths
Expand All @@ -21,5 +24,10 @@
paths = CommonPathHelper.longest_common_paths gvt_output_without_common_paths
expect(paths).to match_array %w[cloud.google.com/go cloud.aws.com/go/metadata]
end

it 'shows all paths when the longest path is a single directory' do
paths = CommonPathHelper.longest_common_paths gvt_output_with_github_common_path
expect(paths).to match_array gvt_output_with_github_common_path
end
end
end

0 comments on commit f1d5423

Please sign in to comment.