Improved 'VAR_VALUE_P1' regex for 'SetParser::parse1' fixing several issues

1. Introduced extra paranethesis at the beggining and end of the regex for
   maching queries surrounded by them like: `( SELECT ... )`.
2. Added explicit SELECT at the beggining to mach queries starting with
   `SELECT`.
2. Introduced a new 'OR' in the first part of the regex: `|(?:NULL)` in
   order to avoid collapsing NULL values followed by commas without spaces.
3. Improved final section of the regex `(?:)` that was previously
   macthing with multiple empty groups, inducing a complete collapse of
   the initial query into an empty value in case of not matching the initial
   capturing group. With the new one, in case of emtpy value the external
   parenthesis are matched, for being remove later from the value.
pull/3451/head
Javier Jaramago Fernández 5 years ago
parent ee3bf049d1
commit a0020a43f2

@ -37,7 +37,7 @@ std::map<std::string,std::vector<std::string>> SetParser::parse1() {
#define VAR_P1 "(@\\w+|\\w+)"
//#define VAR_VALUE "((?:[\\w/\\d:\\+\\-]|,)+)"
//#define VAR_VALUE "((?:CONCAT\\((?:(REPLACE|CONCAT)\\()+@@sql_mode,(?:(?:'|\\w|,| |\"|\\))+(?:\\)))|(?:[@\\w/\\d:\\+\\-]|,)+|(?:)))"
#define VAR_VALUE_P1 "(((?:CONCAT\\()*(?:((?: )*REPLACE|IFNULL|CONCAT)\\()+(?: )*(?:NULL|@OLD_SQL_MODE|@@sql_mode),(?:(?:'|\\w|,| |\"|\\))+(?:\\))*)|(?:[@\\w/\\d:\\+\\-]|,)+|(?:)))"
#define VAR_VALUE_P1 "((?:\\()*(?:SELECT)*(?: )*(?:CONCAT\\()*(?:(?:(?: )*REPLACE|IFNULL|CONCAT)\\()+(?: )*(?:NULL|@OLD_SQL_MODE|@@SQL_MODE),(?:(?:'|\\w|,| |\"|\\))+(?:\\))*)(?:\\))|(?:NULL)|(?:[@\\w/\\d:\\+\\-]|,)+|(?:(?:'{1}|\"{1})(?:)(?:'{1}|\"{1})))"
const std::string pattern="(?:" NAMES SPACES QUOTES NAME_VALUE QUOTES "(?: +COLLATE +" QUOTES NAME_VALUE QUOTES "|)" "|" SESSION_P1 VAR_P1 SPACES "(?:|:)=" SPACES QUOTES VAR_VALUE_P1 QUOTES ") *,? *";
VALGRIND_DISABLE_ERROR_REPORTING;
@ -63,7 +63,11 @@ VALGRIND_ENABLE_ERROR_REPORTING;
// VARIABLE
value5.erase(value5.find_last_not_of(" \n\r\t,")+1);
key = value4;
op.push_back(value5);
if (value5 == "''" || value5 == "\"\"") {
op.push_back("");
} else {
op.push_back(value5);
}
}
std::transform(key.begin(), key.end(), key.begin(), ::tolower);

Loading…
Cancel
Save