diff options
author | Nobuyoshi Nakada <[email protected]> | 2021-01-12 18:17:02 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2021-01-12 20:02:43 +0900 |
commit | 7dc0511ea4be210f82abb1c82a31aec3a4fe5736 (patch) | |
tree | 641de37d2e24fe9c7ba3d30536a7c9b0886537e5 /dir.c | |
parent | ccabf4966f4c5a7e19fec52b690d07bf471fc5d1 (diff) |
Remove "." and ".." from Dir.glob with FNM_DOTMATCH [Bug #17280]
Co-authored-by: Jeremy Evans <[email protected]>
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4052
Diffstat (limited to 'dir.c')
-rw-r--r-- | dir.c | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -222,6 +222,7 @@ typedef enum { #define FNM_SHORTNAME 0 #endif #define FNM_GLOB_NOSORT 0x40 +#define FNM_GLOB_SKIPDOT 0x80 #define FNM_NOMATCH 1 #define FNM_ERROR 2 @@ -2413,6 +2414,10 @@ glob_helper( } return status; } + + int skipdot = (flags & FNM_GLOB_SKIPDOT); + flags |= FNM_GLOB_SKIPDOT; + while ((dp = glob_getent(&globent, flags, enc)) != NULL) { char *buf; rb_pathtype_t new_pathtype = path_unknown; @@ -2423,11 +2428,12 @@ glob_helper( name = dp->d_name; namlen = dp->d_namlen; - if (recursive && name[0] == '.') { + if (name[0] == '.') { ++dotfile; if (namlen == 1) { /* unless DOTMATCH, skip current directories not to recurse infinitely */ - if (!(flags & FNM_DOTMATCH)) continue; + if (recursive && !(flags & FNM_DOTMATCH)) continue; + if (skipdot) continue; ++dotfile; new_pathtype = path_directory; /* force to skip stat/lstat */ } |