skip spaces before and after \<letter> alias

... for proper single letter like `\l`, `\d` handling.

Using `std::search()` for alias substring search instead of `.starts_with()`
to get the alias start position, to check the leading range contains only space
characters, and to get the rest of input after the space.

See issue #9339
This commit is contained in:
Pavel Medvedev 2021-10-31 15:42:30 +01:00
parent f4e3d053c2
commit 7b50ab7136

View File

@ -1366,12 +1366,19 @@ void ClientBase::runInteractive()
for (const auto& [alias, command] : backslash_aliases)
{
if (input.starts_with(alias))
auto it = std::search(input.begin(), input.end(), alias.begin(), alias.end());
if (it != input.end() && std::all_of(input.begin(), it, isWhitespaceASCII))
{
// append the rest of input to the command
// for parameters support, e.g. \c db_name -> USE db_name
input = command + input.substr(alias.size());
break;
it += alias.size();
if (it == input.end() || isWhitespaceASCII(*it))
{
String new_input = command;
// append the rest of input to the command
// for parameters support, e.g. \c db_name -> USE db_name
new_input.append(it, input.end());
input = std::move(new_input);
break;
}
}
}