Bug 16865

Summary: base::glob2rx does not recognise escaped wildcards
Product: R Reporter: Adam Obeng <bugs.r-project.org>
Component: MiscAssignee: R-core <R-core>
Status: UNCONFIRMED ---    
Severity: normal    
Priority: P5    
Version: R 3.2.3   
Hardware: Other   
OS: Other   

Description Adam Obeng 2016-05-04 10:03:29 UTC
Unix glob allows the wildcards to be escaped with a backslash, but glob2rx doesn't. This matters for filenames which contain a literal '*', '?', or other glob wildcard.

Assuming a directory structure like:

├── *.txt
└── anything.txt

> system('ls testdir/\\*.txt')
> Sys.glob('testdir/\\*.txt')
[1] "testdir/*.txt"
> list.files(path='testdir', glob2rx('\\*.txt'))

As expected, glob2rx incorrectly treats this '*' as a wildcard:

> glob2rx('\\*.txt')
[1] "^\\.*\\.txt$"

Although the docs note that glob2rx may not work with arbitrary characters in the pattern, this kind incompatibility might still be unexpected. For example, a naive use of glob2rx on filepaths would allow wildcards to match '/', which glob does not.