From a0020a43f2f6bc13dcf180a28db25e1e36445f94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Wed, 24 Feb 2021 10:55:52 +0000 Subject: [PATCH] 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. --- lib/set_parser.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/set_parser.cpp b/lib/set_parser.cpp index c096fcfc3..4c1931b55 100644 --- a/lib/set_parser.cpp +++ b/lib/set_parser.cpp @@ -37,7 +37,7 @@ std::map> 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);