Bug 16865 - base::glob2rx does not recognise escaped wildcards
Summary: base::glob2rx does not recognise escaped wildcards
Status: UNCONFIRMED
Alias: None
Product: R
Classification: Unclassified
Component: Misc (show other bugs)
Version: R 3.2.3
Hardware: Other Other
: P5 normal
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2016-05-04 10:03 UTC by Adam Obeng
Modified: 2016-05-04 10:03 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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:

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


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

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.