Improve handling of dubious numbers: 0x and 0b

This commit is contained in:
Joanna Hulboj 2022-12-07 20:42:47 +00:00
parent c5296db521
commit b6015a5c02
4 changed files with 60 additions and 4 deletions

View File

@ -113,13 +113,27 @@ Token Lexer::nextTokenImpl()
bool start_of_block = false;
/// 0x, 0b
bool hex = false;
if (pos + 2 < end && *pos == '0' && (pos[1] == 'x' || pos[1] == 'b' || pos[1] == 'X' || pos[1] == 'B') && pos[2] != ';')
if (pos + 2 < end && *pos == '0' && (pos[1] == 'x' || pos[1] == 'b' || pos[1] == 'X' || pos[1] == 'B'))
{
bool is_valid = false;
if (pos[1] == 'x' || pos[1] == 'X')
{
if (isHexDigit(pos[2]))
{
hex = true;
is_valid = true; // hex
}
}
else if (pos[2] == '0' || pos[2] == '1')
is_valid = true; // bin
if (is_valid)
{
pos += 2;
start_of_block = true;
}
else
++pos; // consume the leading zero - could be an identifier
}
else
++pos;

View File

@ -0,0 +1,40 @@
#!/usr/bin/expect -f
set basedir [file dirname $argv0]
set basename [file tail $argv0]
exp_internal -f $env(CLICKHOUSE_TMP)/$basename.debuglog 0
log_user 0
set timeout 60
match_max 100000
set stty_init "rows 25 cols 120"
expect_after {
eof { exp_continue }
timeout { exit 1 }
}
spawn bash
send "source $basedir/../shell_config.sh\r"
send "\$CLICKHOUSE_CLIENT --query 'select 0b'\r"
expect "DB::Exception: Missing columns: '0b' while processing query: 'SELECT `0b`', required columns: '0b'. (UNKNOWN_IDENTIFIER)"
send "\$CLICKHOUSE_CLIENT --query 'select 0b;'\r"
expect "DB::Exception: Missing columns: '0b' while processing query: 'SELECT `0b`', required columns: '0b'. (UNKNOWN_IDENTIFIER)"
send "\$CLICKHOUSE_CLIENT --query 'select 0b ;'\r"
expect "DB::Exception: Missing columns: '0b' while processing query: 'SELECT `0b`', required columns: '0b'. (UNKNOWN_IDENTIFIER)"
send "\$CLICKHOUSE_CLIENT --query 'select 0x'\r"
expect "DB::Exception: Missing columns: '0x' while processing query: 'SELECT `0x`', required columns: '0x'. (UNKNOWN_IDENTIFIER)"
send "\$CLICKHOUSE_CLIENT --query 'select 0x;'\r"
expect "DB::Exception: Missing columns: '0x' while processing query: 'SELECT `0x`', required columns: '0x'. (UNKNOWN_IDENTIFIER)"
send "\$CLICKHOUSE_CLIENT --query 'select 0x ;'\r"
expect "DB::Exception: Missing columns: '0x' while processing query: 'SELECT `0x`', required columns: '0x'. (UNKNOWN_IDENTIFIER)"
send "exit\r"
expect eof

View File

@ -147,6 +147,8 @@ select 0x2_p2; -- { serverError UNKNOWN_IDENTIFIER }
select 0x2p_2; -- { serverError UNKNOWN_IDENTIFIER }
select 0x2p2_; -- { serverError UNKNOWN_IDENTIFIER }
select 0b; -- { serverError UNKNOWN_IDENTIFIER }
select 0b ; -- { serverError UNKNOWN_IDENTIFIER }
select 0x; -- { serverError UNKNOWN_IDENTIFIER }
select 0x ; -- { serverError UNKNOWN_IDENTIFIER }
select 0x_; -- { serverError UNKNOWN_IDENTIFIER }
select 0x_1; -- { serverError UNKNOWN_IDENTIFIER }