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

See Also:


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:

├── *.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.