Skip to content

Commit 4c24a2e

Browse files
committed
Fix bug using spaces in directory names and brackets in filepattern
1 parent d7774d7 commit 4c24a2e

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/filepattern/cpp/internal/filepattern.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ FilePatternObject::FilePatternObject(const string& path, const string& file_patt
1313
this->getPathFromPattern(path); // set path and file_pattern
1414

1515
try {
16-
this->recursive_iterator_ = fs::recursive_directory_iterator(this->getPath());
16+
this->recursive_iterator_ = fs::recursive_directory_iterator(fs::path(this->getPath()));
1717
this->recursive_ = true;
1818
this->setJustPath(true);
1919
} catch (const std::runtime_error& e) {
@@ -37,12 +37,12 @@ FilePatternObject::FilePatternObject(const string& path, const string& file_patt
3737

3838
this->setJustPath(false);
3939
this->setPath(path); // store path to target directory
40-
40+
4141
try {
42-
if(recursive){
43-
this->recursive_iterator_ = fs::recursive_directory_iterator(this->getPath());
42+
if(this->recursive_){
43+
this->recursive_iterator_ = fs::recursive_directory_iterator(fs::path(this->getPath()));
4444
} else{
45-
this->iterator_ = fs::directory_iterator(this->getPath()); // store iterator for target directory
45+
this->iterator_ = fs::directory_iterator(fs::path(this->getPath())); // store iterator for target directory
4646
}
4747
} catch (const std::runtime_error& e) {
4848
string error = "No directory found. Invalid path \"" + path + "\".";
@@ -115,9 +115,9 @@ void FilePatternObject::matchFilesMultDir(){
115115
} else {
116116
file = s::getBaseName(file_path);
117117
}
118-
118+
119119
if(regex_match(file, sm, pattern_regex)){
120-
120+
121121
if(this->getJustPath() || this->captureDirectoryNames()) {
122122
tup = getVariableMap(file_path, sm);
123123
} else {

src/filepattern/cpp/util/util.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ namespace s {
7575
const std::unordered_set<char> escape_chars = {'*', '?', '^', '$', '(', ')', '[', ']', '|'};
7676

7777
for (auto i = 0; i < str.size()-1; ++i) {
78-
if (str[i] == '\\' &&
79-
std::find(std::begin(escape_chars), std::end(escape_chars), str[i+1]) == std::end(escape_chars)
78+
if ((str[i] == '\\' &&
79+
std::find(std::begin(escape_chars), std::end(escape_chars), str[i+1]) == std::end(escape_chars)) ||
80+
str[i] == '/'
8081
) {
8182
return true; // Contains a slash that is not proceeded by a character being escaped
8283
}

0 commit comments

Comments
 (0)