From a627e342f380649c70198942f16c1754b03772da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 16 Mar 2018 09:21:25 +0200 Subject: [PATCH] MXS-1702: Fix minor canonicalization bugs Allow hexadecimal digits if a 0x prefix has been seen. Squash repeating whitespace and remove quotes from quoted strings. --- server/core/modutil.cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/server/core/modutil.cc b/server/core/modutil.cc index 5e06360eb..7d8ada78d 100644 --- a/server/core/modutil.cc +++ b/server/core/modutil.cc @@ -1193,19 +1193,27 @@ static std::pair probe_number(mxs::Buffer::iterator ss_dassert(isdigit(*it)); std::pair rval = std::make_pair(true, it); bool is_hex = *it == '0'; + bool allow_hex = false; // Skip the first character, we know it's a number it++; while (it != end) { - if (!isdigit(*it)) + if (isdigit(*it) || (allow_hex && isxdigit(*it))) { + // Digit or hex-digit, skip it + } + else + { + // Non-digit character + if (is_hex && (*it == 'x' || *it == 'X')) { /** A hexadecimal literal, mark that we've seen the `x` so that * if another one is seen, it is treated as a normal character */ is_hex = false; + allow_hex = true; } else if (*it == 'e') { @@ -1318,7 +1326,7 @@ char* modutil_get_new_canonical(GWBUF* querybuf) case SINGLE_QUOTE: if (*it == '\'') { - rval += "'?'"; + rval += '?'; my_state = NONE; } break; @@ -1326,7 +1334,7 @@ char* modutil_get_new_canonical(GWBUF* querybuf) case DOUBLE_QUOTE: if (*it == '"') { - rval += "\"?\""; + rval += '?'; my_state = NONE; } break; @@ -1334,6 +1342,11 @@ char* modutil_get_new_canonical(GWBUF* querybuf) default: if (isspace(*it)) { + if (isspace(prev)) + { + // Repeating space, skip it + continue; + } *it = ' '; } else if (isdigit(*it) && !isalpha(prev) && !isdigit(prev) && prev != '_')