Safe conversion to user_id in get_link_user_id.

GitOrigin-RevId: 3f0f81deef264b4b0a193cc18ef5bb344490751d
This commit is contained in:
levlam 2018-06-30 02:51:13 +03:00
parent cfd1761a00
commit 4fb3506792

View File

@ -1205,7 +1205,7 @@ string get_first_url(Slice text, const vector<MessageEntity> &entities) {
} }
static UserId get_link_user_id(Slice url) { static UserId get_link_user_id(Slice url) {
auto lower_cased_url = to_lower(url); string lower_cased_url = to_lower(url);
url = lower_cased_url; url = lower_cased_url;
Slice link_scheme("tg:"); Slice link_scheme("tg:");
@ -1236,7 +1236,11 @@ static UserId get_link_user_id(Slice url) {
Slice value; Slice value;
std::tie(key, value) = split(parameter, '='); std::tie(key, value) = split(parameter, '=');
if (key == Slice("id")) { if (key == Slice("id")) {
return UserId(to_integer<int32>(value)); auto r_user_id = to_integer_safe<int32>(value);
if (r_user_id.is_error()) {
return UserId();
}
return UserId(r_user_id.ok());
} }
} }
return UserId(); return UserId();