From: "h.shirosaki (Hiroshi Shirosaki)" Date: 2022-10-14T12:35:30+00:00 Subject: [ruby-core:110281] [Ruby master Bug#19042] Bug: Dir.glob ignores subdirectories in alternation when alternation is preceded by recursive directory pattern Issue #19042 has been updated by h.shirosaki (Hiroshi Shirosaki). If brace patterns have '/', the brace would fail to match here. https://github.com/ruby/ruby/blob/7b413c1db3e65909c6899e1d3be4d16c3e76149c/dir.c#L2327 This may be a fix. Expand brace patterns early if the brace contains '/'. ``` c diff --git a/dir.c b/dir.c index a3ea5eea50..a35aace6f1 100644 --- a/dir.c +++ b/dir.c @@ -2305,7 +2305,7 @@ glob_helper( #endif break; case BRACE: - if (!recursive) { + if (!recursive || strchr(p->str, '/')) { brace = 1; } break; ``` ---------------------------------------- Bug #19042: Bug: Dir.glob ignores subdirectories in alternation when alternation is preceded by recursive directory pattern https://bugs.ruby-lang.org/issues/19042#change-99569 * Author: matthew.kern2 (Matt Kern) * Status: Open * Priority: Normal * ruby -v: 2.7.2 * Backport: 2.7: REQUIRED, 3.0: REQUIRED, 3.1: REQUIRED ---------------------------------------- The Dir.glob method omits results from subdirectories listed in an alternation when that alternation is preceded by a recursive directory pattern (`**/`). Demonstration here: https://replit.com/@MattKern1/Dirglob-subdirectory-alternation-issue?v=1 I have reproduced this in `ruby 2.7.2` and `ruby 3.0.0`. Local output: ``` shell ��� tree . ��������� tmp ��������� dir_a ������� ��������� file_a1.txt ��������� dir_b ��������� subdir ��������� file_b1.txt 4 directories, 2 files ��� irb 2.7.2 :001 > Dir.glob('tmp/{dir_a,dir_b/subdir}/*.txt') => ["tmp/dir_a/file_a1.txt", "tmp/dir_b/subdir/file_b1.txt"] 2.7.2 :002 > Dir.glob('**/{dir_a,dir_b/subdir}/*.txt') => ["tmp/dir_a/file_a1.txt"] 2.7.2 :003 > exit ``` You can see that while the text file in `dir_a` shows up in both examples, the text file in `dir_b/subdir` shows up when the preceding path is explicitly defined, but not when `tmp/` is replaced with the more general recursive directory expression `**/`. Works properly with ruby 2.5.3 ``` 2.5.3 :001 > Dir.glob('tmp/{dir_a,dir_b/subdir}/*.txt') => ["tmp/dir_a/file_a1.txt", "tmp/dir_b/subdir/file_b1.txt"] 2.5.3 :002 > Dir.glob('**/{dir_a,dir_b/subdir}/*.txt') => ["tmp/dir_a/file_a1.txt", "tmp/dir_b/subdir/file_b1.txt"] ``` This seems related to this line of code: https://github.com/ruby/ruby/blob/7b413c1db3e65909c6899e1d3be4d16c3e76149c/dir.c#L2140 I'm not sure exactly what changed between version 2.5.3 and 2.7.2, but there do appear to be some significant code changes (and the order of results from Dir.glob is sometimes different). Possibly related to this discussion? https://bugs.ruby-lang.org/issues/17280 -- https://bugs.ruby-lang.org/ Unsubscribe: