Skip to content

Commit

Permalink
[Fix #9593] Fix an error when processing a directory is named {}
Browse files Browse the repository at this point in the history
Fixes #9593.

This PR fixes the following error when processing a directory is named `{}`.

```console
% mkdir {}
% rubocop
(snip)

File name too long - /tmp//////////////////////////////////////////////...
```
  • Loading branch information
koic authored and bbatsov committed Mar 12, 2021
1 parent 3148062 commit 027655d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
@@ -0,0 +1 @@
* [#9593](https://github.com/rubocop/rubocop/issues/9593): Fix an error when processing a directory is named `{}`. ([@koic][])
1 change: 1 addition & 0 deletions lib/rubocop/target_finder.rb
Expand Up @@ -96,6 +96,7 @@ def find_files(base_dir, flags)
end

def wanted_dir_patterns(base_dir, exclude_pattern, flags)
base_dir = base_dir.gsub('/{}/', '/\{}/')
dirs = Dir.glob(File.join(base_dir.gsub('/**/', '/\**/'), '*/'), flags)
.reject do |dir|
dir.end_with?('/./', '/../') || File.fnmatch?(exclude_pattern, dir, flags)
Expand Down
13 changes: 13 additions & 0 deletions spec/rubocop/target_finder_spec.rb
Expand Up @@ -441,6 +441,19 @@
expect(found_basenames).to include('ruby4.rb')
end

it 'works also if a folder is named "{}"' do
create_empty_file('{}/ruby4.rb')

config = instance_double(RuboCop::Config)
exclude_property = { 'Exclude' => [File.expand_path('dir1/**/*')] }
allow(config).to receive(:for_all_cops).and_return(exclude_property)
allow(config_store).to receive(:for).and_return(config)

expect(found_basenames).not_to include('ruby1.rb')
expect(found_basenames).to include('ruby3.rb')
expect(found_basenames).to include('ruby4.rb')
end

# Cannot create a directory with containing `*` character on Windows.
# https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions
unless RuboCop::Platform.windows?
Expand Down

0 comments on commit 027655d

Please sign in to comment.