Canonicalized queries remove non-executable comments

The comments which do not alter the functionality of a query are now removed
from canonicalized queries.

Also fixed missing semicolon in the comment removal regex and added tests
for comment removal.
This commit is contained in:
Markus Makela
2016-01-11 12:25:33 +02:00
parent 8ee110efa8
commit 54ca1ab2de
4 changed files with 32 additions and 3 deletions

View File

@ -2034,13 +2034,13 @@ void skygw_file_close(
#define BUFFER_GROWTH_RATE 1.2
static pcre2_code* remove_comments_re = NULL;
static const PCRE2_SPTR remove_comments_pattern = (PCRE2_SPTR)
"(?:`[^`]*`\\K)|(?:#.*|--[[:space]].*)";
"(?:`[^`]*`\\K)|(\\/[*](?!(M?!)).*?[*]\\/)|(?:#.*|--[[:space:]].*)";
/**
* Remove SQL comments from the end of a string
*
* The inline comments are not removed due to the fact that they can alter the
* behavior of the query.
* The inline executable comments are not removed due to the fact that they can
* alter the behavior of the query.
* @param src Pointer to the string to modify.
* @param srcsize Pointer to a size_t variable which holds the length of the string to
* be modified.