summaryrefslogtreecommitdiff
path: root/spec/ruby/core/dir
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-01-12 18:17:02 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-01-12 20:02:43 +0900
commit7dc0511ea4be210f82abb1c82a31aec3a4fe5736 (patch)
tree641de37d2e24fe9c7ba3d30536a7c9b0886537e5 /spec/ruby/core/dir
parentccabf4966f4c5a7e19fec52b690d07bf471fc5d1 (diff)
Remove "." and ".." from Dir.glob with FNM_DOTMATCH [Bug #17280]
Co-authored-by: Jeremy Evans <code@jeremyevans.net>
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4052
Diffstat (limited to 'spec/ruby/core/dir')
-rw-r--r--spec/ruby/core/dir/fixtures/common.rb10
-rw-r--r--spec/ruby/core/dir/glob_spec.rb37
-rw-r--r--spec/ruby/core/dir/shared/glob.rb42
3 files changed, 70 insertions, 19 deletions
diff --git a/spec/ruby/core/dir/fixtures/common.rb b/spec/ruby/core/dir/fixtures/common.rb
index 71b1438b72..a1ea3db215 100644
--- a/spec/ruby/core/dir/fixtures/common.rb
+++ b/spec/ruby/core/dir/fixtures/common.rb
@@ -169,4 +169,14 @@ module DirSpecs
subdir_two
]
end
+
+ if RUBY_VERSION > '3.1'
+ def self.expected_glob_paths
+ expected_paths - ['..']
+ end
+ else
+ def self.expected_glob_paths
+ expected_paths
+ end
+ end
end
diff --git a/spec/ruby/core/dir/glob_spec.rb b/spec/ruby/core/dir/glob_spec.rb
index 9b6e2b2d3d..61553ab0b1 100644
--- a/spec/ruby/core/dir/glob_spec.rb
+++ b/spec/ruby/core/dir/glob_spec.rb
@@ -39,7 +39,7 @@ describe "Dir.glob" do
end
it "matches both dot and non-dotfiles with '*' and option File::FNM_DOTMATCH" do
- Dir.glob('*', File::FNM_DOTMATCH).sort.should == DirSpecs.expected_paths
+ Dir.glob('*', File::FNM_DOTMATCH).sort.should == DirSpecs.expected_glob_paths
end
it "matches files with any beginning with '*<non-special characters>' and option File::FNM_DOTMATCH" do
@@ -47,7 +47,7 @@ describe "Dir.glob" do
end
it "matches any files in the current directory with '**' and option File::FNM_DOTMATCH" do
- Dir.glob('**', File::FNM_DOTMATCH).sort.should == DirSpecs.expected_paths
+ Dir.glob('**', File::FNM_DOTMATCH).sort.should == DirSpecs.expected_glob_paths
end
it "recursively matches any subdirectories except './' or '../' with '**/' from the current directory and option File::FNM_DOTMATCH" do
@@ -70,16 +70,31 @@ describe "Dir.glob" do
Dir.glob('**/', File::FNM_DOTMATCH).sort.should == expected
end
- it "recursively matches files and directories in nested dot subdirectory with 'nested/**/*' from the current directory and option File::FNM_DOTMATCH" do
- expected = %w[
- nested/.
- nested/.dotsubir
- nested/.dotsubir/.
- nested/.dotsubir/.dotfile
- nested/.dotsubir/nondotfile
- ]
+ ruby_version_is ''...'3.1' do
+ it "recursively matches files and directories in nested dot subdirectory with 'nested/**/*' from the current directory and option File::FNM_DOTMATCH" do
+ expected = %w[
+ nested/.
+ nested/.dotsubir
+ nested/.dotsubir/.
+ nested/.dotsubir/.dotfile
+ nested/.dotsubir/nondotfile
+ ]
- Dir.glob('nested/**/*', File::FNM_DOTMATCH).sort.should == expected.sort
+ Dir.glob('nested/**/*', File::FNM_DOTMATCH).sort.should == expected.sort
+ end
+ end
+
+ ruby_version_is '3.1' do
+ it "recursively matches files and directories in nested dot subdirectory except . with 'nested/**/*' from the current directory and option File::FNM_DOTMATCH" do
+ expected = %w[
+ nested/.
+ nested/.dotsubir
+ nested/.dotsubir/.dotfile
+ nested/.dotsubir/nondotfile
+ ]
+
+ Dir.glob('nested/**/*', File::FNM_DOTMATCH).sort.should == expected.sort
+ end
end
# This is a separate case to check **/ coming after a constant
diff --git a/spec/ruby/core/dir/shared/glob.rb b/spec/ruby/core/dir/shared/glob.rb
index f6d41ba209..c35f7d71ca 100644
--- a/spec/ruby/core/dir/shared/glob.rb
+++ b/spec/ruby/core/dir/shared/glob.rb
@@ -121,8 +121,16 @@ describe :dir_glob, shared: true do
Dir.send(@method, 'special/test\{1\}/*').should == ['special/test{1}/file[1]']
end
- it "matches dotfiles with '.*'" do
- Dir.send(@method, '.*').sort.should == %w|. .. .dotfile .dotsubdir|.sort
+ ruby_version_is ''...'3.1' do
+ it "matches dotfiles with '.*'" do
+ Dir.send(@method, '.*').sort.should == %w|. .. .dotfile .dotsubdir|.sort
+ end
+ end
+
+ ruby_version_is '3.1' do
+ it "matches dotfiles except .. with '.*'" do
+ Dir.send(@method, '.*').sort.should == %w|. .dotfile .dotsubdir|.sort
+ end
end
it "matches non-dotfiles with '*<non-special characters>'" do
@@ -167,8 +175,16 @@ describe :dir_glob, shared: true do
Dir.send(@method, '**').sort.should == expected
end
- it "matches dotfiles in the current directory with '.**'" do
- Dir.send(@method, '.**').sort.should == %w|. .. .dotsubdir .dotfile|.sort
+ ruby_version_is ''...'3.1' do
+ it "matches dotfiles in the current directory with '.**'" do
+ Dir.send(@method, '.**').sort.should == %w|. .. .dotsubdir .dotfile|.sort
+ end
+ end
+
+ ruby_version_is '3.1' do
+ it "matches dotfiles in the current directory except .. with '.**'" do
+ Dir.send(@method, '.**').sort.should == %w|. .dotsubdir .dotfile|.sort
+ end
end
it "recursively matches any nondot subdirectories with '**/'" do
@@ -189,9 +205,19 @@ describe :dir_glob, shared: true do
Dir.send(@method, '**/').sort.should == expected
end
- it "recursively matches any subdirectories including ./ and ../ with '.**/'" do
- Dir.chdir("#{DirSpecs.mock_dir}/subdir_one") do
- Dir.send(@method, '.**/').sort.should == %w|./ ../|.sort
+ ruby_version_is ''...'3.1' do
+ it "recursively matches any subdirectories including ./ and ../ with '.**/'" do
+ Dir.chdir("#{DirSpecs.mock_dir}/subdir_one") do
+ Dir.send(@method, '.**/').sort.should == %w|./ ../|.sort
+ end
+ end
+ end
+
+ ruby_version_is '3.1' do
+ it "recursively matches any subdirectories including ./ with '.**/'" do
+ Dir.chdir("#{DirSpecs.mock_dir}/subdir_one") do
+ Dir.send(@method, '.**/').should == ['./']
+ end
end
end
@@ -234,7 +260,7 @@ describe :dir_glob, shared: true do
end
it "matches dot or non-dotfiles with '{,.}*'" do
- Dir.send(@method, '{,.}*').sort.should == DirSpecs.expected_paths
+ Dir.send(@method, '{,.}*').sort.should == DirSpecs.expected_glob_paths
end
it "respects the order of {} expressions, expanding left most first" do