Skip to content

Commit

Permalink
[Fix rubocop#10200] Fix an error when inspecting a directory named *
Browse files Browse the repository at this point in the history
Fixes rubocop#10200.

This PR fixes an error when inspecting a directory named `*`.
  • Loading branch information
koic committed Oct 20, 2021
1 parent 5b27789 commit 63ea6e6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_error_when_inspecting_dir_named_wildcard.md
@@ -0,0 +1 @@
* [#10200](https://github.com/rubocop/rubocop/issues/10200): Fix an error when inspecting a directory named `*`. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/target_finder.rb
Expand Up @@ -95,7 +95,7 @@ def find_files(base_dir, flags)

def wanted_dir_patterns(base_dir, exclude_pattern, flags)
base_dir = base_dir.gsub('/{}/', '/\{}/')
dirs = Dir.glob(File.join(base_dir.gsub('/**/', '/\**/'), '*/'), flags)
dirs = Dir.glob(File.join(base_dir.gsub('/*/', '/\*/').gsub('/**/', '/\**/'), '*/'), flags)
.reject do |dir|
next true if dir.end_with?('/./', '/../')
next true if File.fnmatch?(exclude_pattern, dir, flags)
Expand Down
14 changes: 14 additions & 0 deletions spec/rubocop/cli_spec.rb
Expand Up @@ -258,6 +258,20 @@ def and_with_args
end
end
end

context 'when a directory is named `*`' do
before do
FileUtils.mkdir('*')
end

after do
FileUtils.rmdir('*')
end

it 'does not crash' do
expect(cli.run([])).to eq(0)
end
end
end

describe 'rubocop:disable comment' do
Expand Down

0 comments on commit 63ea6e6

Please sign in to comment.