fakefs / fakefs

A fake filesystem. Use it in your tests.
MIT License
1.04k stars 188 forks source link

Dir.glob fails if chdir to a directory that contains plus signs '+' #451

Closed gyfelton closed 3 years ago

gyfelton commented 3 years ago

Original code that reproduces the error. Assuming the following file is created by FakeFS: tmp/abc+cde/content.txt

Dir.chdir('/tmp/abc+cde').do 
   Dir.glob('**/*') do |file|
      # Expected: content.txt
      # Actual: tmp/abc+cde/content.txt
   end
end

The reason for above is because in self.glob method of dir.rb, %r{\A#{Dir.pwd}/?} is evaluated as \/tmp\/abc+cde when it should be \/tmp\/abc\+cde (%r only escapes / not +)

The following test should be success when it is failing:

def test_dir_glob_special_char_in_dir_name
    FileUtils.mkdir_p '/abc+cde/python-3.4.1'
    FileUtils.mkdir_p '/abc+cde/python-2.7.8'
    Dir.chdir('/abc+cde') do
      assert_equal ['python-2.7.8', 'python-3.4.1'], Dir.glob('**/*')
    end
end
grosser commented 3 years ago

PR welcome, thx for the test!

gyfelton commented 3 years ago

@grosser Thanks, curious if using a fix on Globber will help here: https://github.com/fakefs/fakefs/issues/133

grosser commented 3 years ago

that's already released, so it does not work ? (you tried with latest ?)

On Tue, Dec 1, 2020 at 9:57 AM Elton Gao notifications@github.com wrote:

@grosser https://github.com/grosser Thanks, curious if using a fix on Globber will help here: #133 https://github.com/fakefs/fakefs/issues/133

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/fakefs/fakefs/issues/451#issuecomment-736719125, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAACYZZLHAHKKNAVNGZKI3LSSUU7DANCNFSM4UJJFZRQ .

gyfelton commented 3 years ago

resolved by above PR