Fix whitespace in canonicalized queries

Trailing whitespace was not removed and whitespace wasn't normalized to
spaces.
This commit is contained in:
Markus Mäkelä
2019-04-11 10:21:41 +03:00
parent d2ecaa83a6
commit 1652b18a7b

View File

@ -1459,9 +1459,16 @@ std::string get_canonical(GWBUF* querybuf)
break;
}
}
else if (is_space(*it) && (i == 0 || is_space(rval[i - 1])))
else if (is_space(*it))
{
// Repeating space, skip it
if (i == 0 || is_space(rval[i - 1]))
{
// Leading or repeating whitespace, skip it
}
else
{
rval[i++] = ' ';
}
}
else if (*it == '/' && is_next(it, buf.end(), "/*"))
{
@ -1565,6 +1572,12 @@ std::string get_canonical(GWBUF* querybuf)
mxb_assert(it != buf.end());
}
// Remove trailing whitespace
while (i > 0 && is_space(rval[i - 1]))
{
--i;
}
// Shrink the buffer so that the internal bookkeeping of std::string remains up to date
rval.resize(i);