mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 01:51:59 +00:00
Improve handling of dubious numbers: 0x and 0b
This commit is contained in:
parent
c5296db521
commit
b6015a5c02
@ -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;
|
||||
|
||||
|
40
tests/queries/0_stateless/02493_inconsistent_hex_and_binary_number.expect
Executable file
40
tests/queries/0_stateless/02493_inconsistent_hex_and_binary_number.expect
Executable 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
|
@ -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 }
|
||||
|
Loading…
Reference in New Issue
Block a user