diff --git a/src/common/backend/parser/gram.y b/src/common/backend/parser/gram.y index 3ca55fb97f9a1b74d7887db109604cf937549ba7..96e954cd75152557e65b2fdd71261964b2b8e7d0 100644 --- a/src/common/backend/parser/gram.y +++ b/src/common/backend/parser/gram.y @@ -31336,6 +31336,8 @@ static CharsetCollateOptions* MakeCharsetCollateOptions(CharsetCollateOptions *o static char* GetValidUserHostId(char* userName, char* hostId) { CheckUserHostIsValid(); + if (strchr(userName,'@')) + ereport(ERROR,(errcode(ERRCODE_INVALID_NAME),errmsg("@ can't be allowed in username"))); char* userHostId = NULL; if (*hostId == '\'') { userHostId = hostId + 1; diff --git a/src/test/regress/input/user_host_test.source b/src/test/regress/input/user_host_test.source index 9b84c25f450292b90744fad9e72d32894a53ace3..12699ddddcb4af0db3c0ef595c40ccfcd6e7f241 100644 --- a/src/test/regress/input/user_host_test.source +++ b/src/test/regress/input/user_host_test.source @@ -17,6 +17,7 @@ create user 'test_user_host'@'127.0.%' password 'test123@'; create user 'test_user_host%' password 'test123@'; create user 'test_user_host'@'127.0.0.1' password 'test123@'; set b_compatibility_user_host_auth = on; +CREATE USER 'da@localhost'@'%' PASSWORD 'test123@'; create user if not exists 'test_user_host'@'%' password 'test123@'; alter user 'test_user_host'@'%' with account lock; alter user 'test_user_host'@'%' password 'test1234@'; diff --git a/src/test/regress/output/user_host_test.source b/src/test/regress/output/user_host_test.source index c666fd043645557f843a906a221e0b05d17782d5..a150e999c06ad1a38b92ecc924c28b3cd3342fa1 100644 --- a/src/test/regress/output/user_host_test.source +++ b/src/test/regress/output/user_host_test.source @@ -48,6 +48,8 @@ LINE 1: create user 'test_user_host%' password 'test123@'; create user 'test_user_host'@'127.0.0.1' password 'test123@'; ERROR: user@host is only supported in b database when the b_compatibility_user_host_auth is on set b_compatibility_user_host_auth = on; +CREATE USER 'da@localhost'@'%' PASSWORD 'test123@'; +ERROR: @ can't be allowed in username create user if not exists 'test_user_host'@'%' password 'test123@'; alter user 'test_user_host'@'%' with account lock; alter user 'test_user_host'@'%' password 'test1234@';