Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Commit

Permalink
(FACT-2650) Fix bug with wrong slashes in external fact file paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Filipovici committed Jun 9, 2020
1 parent 7f64b49 commit 58649f7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,4 @@



\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*


\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
2 changes: 2 additions & 0 deletions lib/custom_facts/util/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def load_all

paths = search_path
paths&.each do |dir|
# clean the search path of wrong slashes and backslashes
dir = dir.gsub(%r{[\/\\]+}, File::SEPARATOR)
# dir is already an absolute path
Dir.glob(File.join(dir, '*.rb')).each do |path|
# exclude dirs that end with .rb
Expand Down
18 changes: 18 additions & 0 deletions spec/custom_facts/util/loader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,24 @@ def loader_from(places)
loader.load_all
loader.load_all
end

context 'when directory path has wrong slashes' do
before do
allow(Dir).to receive(:glob).with('/one/dir/*.rb').and_return %w[/one/dir/a.rb]
end

dir_paths = ['//one///dir', '//one///\\dir', '/one///\/\dir', '\one///\\dir']

dir_paths.each do |dir_path|
it 'corrects the directory path' do
allow(loader).to receive(:search_path).and_return [dir_path]

loader.load_all

expect(Dir).to have_received(:glob).with('/one/dir/*.rb')
end
end
end
end

it 'loads facts on the facter search path only once' do
Expand Down

0 comments on commit 58649f7

Please sign in to comment.