Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #10200] Fix an error when inspecting a directory named * #10201

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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