Issue #8258 has been updated by Eregon (Benoit Daloze).


headius (Charles Nutter) wrote:
> rkh (Konstantin Haase) wrote:
> > File.fnmatch_escape would make more sense, imo.
> 
> But it would be harder to remember when what you want is "glob" :-)
> 
> Why not just {Dir,File}.quote or .escape, to match Regexp.quote/escape? I would vote for File.escape, a method that escapes any file path to make it suitable for globbing.

I agree, this would be strictly superior.

I guess the most common use case is globbing on a directory recursively, so only the base directory is to be escaped, but this is not worth a specific method I think and could be done easily: Dir.glob("#{Dir.escape dir}/**/*.rb") { |file| ... }
Pathname could likely avoid this problem nicely in this situation: dir = Pathname("some_dir"); dir.glob("**/*.rb") { |file| ... }
----------------------------------------
Feature #8258: Dir#escape_glob
https://bugs.ruby-lang.org/issues/8258#change-38537

Author: steveklabnik (Steve Klabnik)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


This is inspired by https://github.com/rails/rails/issues/6010.

Basically, if you do a Dir.glob in a directory whose name contains a glob character, things break. It would be nice to have a method which would escape the input so that we can Dir.glob inside of those directories.


-- 
http://bugs.ruby-lang.org/