Project

General

Profile

Actions

Bug #17280

closed

Dir.glob with FNM_DOTMATCH matches ".." and "." and results in duplicated entries

Added by Eregon (Benoit Daloze) about 4 years ago. Updated almost 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]
[ruby-core:100504]

Description

% ruby -e 'p Dir.glob("**/*", File::FNM_DOTMATCH)'
[".", "bar", "bar/.", "bar/.baz", "bar/.baz/.", "bar/.baz/qux"]
% ruby -e 'p Dir.glob("**", File::FNM_DOTMATCH)' 
[".", "..", "bar"]
% ruby -e 'p Dir.glob("*", File::FNM_DOTMATCH)' 
[".", "..", "bar"]

I think ".." was never intended by the user here, is it a bug?

Not sure about ".".

Note it also causes duplicated entries: bar and bar/.baz are twice in the Array!

I think .. should always be ignored for glob purposes, it escapes the current directory.
And . seems useless and causing duplicates.

I think the intention of users of File::FNM_DOTMATCH is to match file/directories starting with a . like .baz.
Probably Dir.glob("**/{*,.*}") is a safer way to achieve that,
but still I think FNM_DOTMATCH should not produce such weird results.

From https://github.com/oracle/truffleruby/issues/2116
I could not figure out what was the intended semantics for FNM_DOTMATCH with regards to . and ...


Related issues 3 (0 open3 closed)

Related to Ruby master - Bug #16831: Running `Pathname#glob` with `File::FNM_DOTMATCH` option loses `.` and `..`ClosedActions
Related to Ruby master - Bug #17283: Why does Dir.glob's ** match files in current directory?ClosedActions
Related to Ruby master - Bug #18436: Fix Pathname dot directory globbingClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0