diff --git a/changelog/fix_error_when_inspecting_dir_named_wildcard.md b/changelog/fix_error_when_inspecting_dir_named_wildcard.md new file mode 100644 index 00000000000..dd7d0d465c2 --- /dev/null +++ b/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][]) diff --git a/lib/rubocop/target_finder.rb b/lib/rubocop/target_finder.rb index e113f3f9aa2..9a2adb4f8b4 100644 --- a/lib/rubocop/target_finder.rb +++ b/lib/rubocop/target_finder.rb @@ -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) diff --git a/spec/rubocop/cli_spec.rb b/spec/rubocop/cli_spec.rb index d086fe78c04..7db28135fd8 100644 --- a/spec/rubocop/cli_spec.rb +++ b/spec/rubocop/cli_spec.rb @@ -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