diff --git a/CHANGELOG.md b/CHANGELOG.md index c663c6726..6b2955c0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)* diff --git a/lib/custom_facts/util/loader.rb b/lib/custom_facts/util/loader.rb index d8a909e91..f37bae1e5 100644 --- a/lib/custom_facts/util/loader.rb +++ b/lib/custom_facts/util/loader.rb @@ -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 diff --git a/spec/custom_facts/util/loader_spec.rb b/spec/custom_facts/util/loader_spec.rb index 6e803b8f9..b01ce4d7a 100755 --- a/spec/custom_facts/util/loader_spec.rb +++ b/spec/custom_facts/util/loader_spec.rb @@ -280,6 +280,22 @@ 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 + end + end + end end it 'loads facts on the facter search path only once' do