Simplify match_url code.

This commit is contained in:
levlam 2022-08-20 11:34:21 +03:00
parent 0d2ddc2d56
commit 4206246b0c
2 changed files with 4 additions and 14 deletions

View File

@ -748,23 +748,12 @@ static vector<Slice> match_urls(Slice str) {
const unsigned char *last_at_ptr = nullptr;
const unsigned char *domain_end_ptr = begin + dot_pos;
if (domain_begin_ptr == begin || domain_begin_ptr[-1] != '@') {
// try to find '@' to the right if there is no '@' to the left
while (domain_end_ptr != end) {
uint32 code = 0;
auto next_ptr = next_utf8_unsafe(domain_end_ptr, &code);
if (code == '@') {
last_at_ptr = domain_end_ptr;
} else if (!is_domain_symbol(code)) {
break;
}
domain_end_ptr = next_ptr;
}
}
while (domain_end_ptr != end) {
uint32 code = 0;
auto next_ptr = next_utf8_unsafe(domain_end_ptr, &code);
if (!is_domain_symbol(code)) {
if (code == '@') {
last_at_ptr = domain_end_ptr;
} else if (!is_domain_symbol(code)) {
break;
}
domain_end_ptr = next_ptr;

View File

@ -704,6 +704,7 @@ TEST(MessageEntities, url) {
check_url("http://test―@―google―.―com―/―–―‐―/―/―/―?―‑―#―――", {"http://test―@―google―.―com―/―–―‐―/―/―/―?―‑―#―――"});
check_url("http://google.com/‖", {"http://google.com/"});
check_url("a@b@c.com", {}, {});
check_url("abc@c.com@d.com", {});
check_url("a@b.com:c@1", {}, {"a@b.com"});
check_url("test@test.software", {}, {"test@test.software"});
check_url("a:b?@gmail.com", {});