Skip to content
Snippets Groups Projects
Commit 6e54618d authored by Marco Biasini's avatar Marco Biasini
Browse files

properly escape special characters in glob pattern

parent ac1e0c09
Branches
Tags
No related merge requests found
...@@ -120,6 +120,7 @@ StringOrRegexParam::StringOrRegexParam(): ...@@ -120,6 +120,7 @@ StringOrRegexParam::StringOrRegexParam():
StringOrRegexParam::StringOrRegexParam(const String& s): StringOrRegexParam::StringOrRegexParam(const String& s):
is_regex_(false),r_(),s_(s) is_regex_(false),r_(),s_(s)
{ {
String special("[]{}()");
for(String::const_iterator it=s.begin();it!=s.end();++it) { for(String::const_iterator it=s.begin();it!=s.end();++it) {
if((*it)=='?' || (*it)=='*') { if((*it)=='?' || (*it)=='*') {
is_regex_=true; is_regex_=true;
...@@ -130,12 +131,16 @@ StringOrRegexParam::StringOrRegexParam(const String& s): ...@@ -130,12 +131,16 @@ StringOrRegexParam::StringOrRegexParam(const String& s):
if(is_regex_) { if(is_regex_) {
std::ostringstream e; std::ostringstream e;
for(String::const_iterator it=s.begin();it!=s.end();++it) { for(String::const_iterator it=s.begin();it!=s.end();++it) {
if((*it)=='?') {
e << "."; if((*it)=='?' && (it==s.begin() || (*(it-1))!='\\')) {
} else if((*it)=='*') { e << ".";
e << ".*"; } else if((*it)=='*' && (it==s.begin() || (*(it-1))!='\\')) {
e << ".*";
} else { } else {
e << *it; if (special.find(*it)!=String::npos) {
e << '\\';
}
e << *it;
} }
} }
//std::cerr << "assembling regex [" << e.str() << "]... "; //std::cerr << "assembling regex [" << e.str() << "]... ";
......
...@@ -148,7 +148,7 @@ QueryToken QueryLexer::LexNumericToken() { ...@@ -148,7 +148,7 @@ QueryToken QueryLexer::LexNumericToken() {
} }
bool is_ident_or_str(char c) { bool is_ident_or_str(char c) {
static String allowed_chars("_*?"); static String allowed_chars("_*?\\");
return isalnum(c) || allowed_chars.find_first_of(c)!=String::npos; return isalnum(c) || allowed_chars.find_first_of(c)!=String::npos;
} }
...@@ -158,7 +158,8 @@ QueryToken QueryLexer::LexIdentOrStringToken() { ...@@ -158,7 +158,8 @@ QueryToken QueryLexer::LexIdentOrStringToken() {
bool force_string=false; bool force_string=false;
while (current_<query_string_.length() && while (current_<query_string_.length() &&
is_ident_or_str(query_string_[current_])) { is_ident_or_str(query_string_[current_])) {
if (query_string_[current_]=='*' || query_string_[current_]=='?') { if (query_string_[current_]=='*' || query_string_[current_]=='?' ||
query_string_[current_]=='\\') {
force_string=true; force_string=true;
} }
current_++; current_++;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment