Project

General

Profile

Bug #16391 ยป dlbdirbug.rb

Demonstration script - dbuck (Dave Buck), 12/02/2019 06:32 PM

 
1
# vim: ts=2 sw=2 et ai
2
#
3
# Version:
4
#           ruby 2.6.5p114 (2019-10-01 revision 67812) [x64-mingw32]
5
#           
6
# Summary: Dir globbing case sensitivity inconsistencies
7
#
8
# Details: directory globbing case sensitivity is os-dependent
9
#          (https://ruby-doc.org/core-2.6.5/Dir.html, glob,
10
#          "Case sensitivity depends on your system");
11
#          On Windows 10, directory globbing is case insensitive,
12
#          and may return glob matches that do
13
#          not match the case of the query.
14
#          Unfortunately, File.fnmatch seems to be case sensitive,
15
#          so this is not a workaround.
16
#
17
# Expected:
18
#         If Dir.pwd => 'C:/users/dave/Documents' (lower case for users)
19
#         then Dir[Dir.pwd+'/*'] => ['C:/users/dave/Documents/...',...]
20
#         (lower case for users), not [C:/Users/dave/Documents/...',...]
21
#
22
#
23
# Impact:
24
#          Rails 6.0 Activeview implementation has an assumption that
25
#          case is sensitive.
26
#
27
# Demonstration:
28
#          The below script yields the following output. Note that
29
#          Dir.pwd yields C:/users..., where a Dir glob of files in
30
#          that directory is prefixed with C:/Users...
31

    
32
cd = Dir.pwd
33
puts "Dir.pwd => '#{cd}'"
34
cds = cd + '/*'
35
fm0 = Dir[cds][0]
36
puts "Dir['#{cds}'][0] => '#{fm0}'"
37
puts "Does the first matching entry match the base path of the query?"
38
m = fm0.start_with? cd
39
p m
40
# How about File.fnmatch?
41
m2 = File.fnmatch cds,fm0
42
puts "fnmatch: #{m2}"
43

    
44
#=> Dir.pwd => 'C:/users/dave/Documents/rails'
45
#=> Dir['C:/users/dave/Documents/rails/*'][0] => 'C:/Users/dave/Documents/rails/blog'
46
#=> Does the first matching entry match the base path of the query?
47
#=> false
48
#=> fnmatch: false