Misc #14905
closedStrange behavior in Dir.glob using ** operator
Description
Hello,
I didn't want to report this as a bug because I'm not sure if it's intentional or not. The documentation didn't say either way. The **
operator appears to work somewhat strangely when used in certain contexts.
An example setup to trigger the odd behavior looks something like this:
human_records
├ person1 ─ records.yml
└ person2 ─ other_records.yml
cloud_records
├ AWS ┬ project1 ─ records.yml
│ └ project2 ─ records.yml
└ Azure ─ azproj1 ─ records.yml
Though the documentation doesn't say to do this, because of my experience with other globbing libraries, I did the following:
Dir.glob("human_records/**.{yml,yaml}")
# => ["human-records/person1/records.yml", "human_records/person2/other_records.yml"]
Dir.glob("cloud_records/**.{yml,yaml}")
# => []
So using **
like this works if there is only one level of folders between the root and the target files, as if the glob was "records/*/*.{yml,yaml}"
.
This seems like undefined behavior, so I thought I would bring it to your attention. If a change isn't a good solution to this, would a note in the documentation about undefined behavior around **
be warranted?