From d2e4f74c5236a814c965377abfee19c9e60240fb Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 25 Jun 2018 03:22:56 +0300 Subject: [PATCH] Match new server parsing of # in URLs. GitOrigin-RevId: f1e26ad10c80721db14132fd3fc3ba17aa2db509 --- td/telegram/MessageEntity.cpp | 2 +- test/message_entities.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/td/telegram/MessageEntity.cpp b/td/telegram/MessageEntity.cpp index b1190056e..01f7d0e48 100644 --- a/td/telegram/MessageEntity.cpp +++ b/td/telegram/MessageEntity.cpp @@ -542,7 +542,7 @@ static vector match_urls(Slice str) { while (bad_path_end_chars.find(path_end_ptr[-1]) < bad_path_end_chars.size()) { path_end_ptr--; } - if (url_end_ptr[0] == '/' || url_end_ptr[0] == '#' || path_end_ptr > url_end_ptr + 1) { + if (url_end_ptr[0] == '/' || path_end_ptr > url_end_ptr + 1) { url_end_ptr = path_end_ptr; } } diff --git a/test/message_entities.cpp b/test/message_entities.cpp index d40127b83..208df414e 100644 --- a/test/message_entities.cpp +++ b/test/message_entities.cpp @@ -360,7 +360,7 @@ TEST(MessageEntities, url) { check_url("http://a.0", {}); check_url("http://a.a", {}); check_url("google.com:1#ab c", {"google.com:1#ab"}); - check_url("google.com:1#", {"google.com:1#"}); + check_url("google.com:1#", {"google.com:1"}); check_url("google.com:1#1", {"google.com:1#1"}); check_url("google.com:00000001/abs", {"google.com:00000001/abs"}); check_url("google.com:000000065535/abs", {"google.com:000000065535/abs"}); @@ -407,7 +407,8 @@ TEST(MessageEntities, url) { check_url("bbbbbbbbbbbbbb.@.@", {}); check_url("http://google.com/", {"http://google.com/"}); check_url("http://google.com?", {"http://google.com"}); - check_url("http://google.com#", {"http://google.com#"}); + check_url("http://google.com#", {"http://google.com"}); + check_url("http://google.com##", {"http://google.com##"}); check_url("http://google.com/?", {"http://google.com/"}); check_url("https://www.google.com/ab,", {"https://www.google.com/ab"}); check_url("@.", {}); @@ -469,7 +470,7 @@ TEST(MessageEntities, url) { "google.com/", "google.com/#", "google.com", - "google.com#"}); + "google.com"}); check_url("https://t.…", {}); check_url("('http://telegram.org/a-b/?br=ie&lang=en',)", {"http://telegram.org/a-b/?br=ie&lang=en"}); check_url("https://ai.telegram.org/bot%20bot/test-...", {"https://ai.telegram.org/bot%20bot/test-"}); @@ -517,7 +518,7 @@ TEST(MessageEntities, url) { check_url("Look :test@example.com", {":test@example.com"}, {}); // TODO {}, {"test@example.com"} check_url("Look mailto:test@example.com", {}, {"test@example.com"}); check_url("http://test.com#a", {"http://test.com#a"}); - check_url("http://test.com#", {"http://test.com#"}); + check_url("http://test.com#", {"http://test.com"}); check_url("http://test.com?#", {"http://test.com?#"}); check_url("http://test.com/?#", {"http://test.com/?#"}); check_url("https://t.me/abcdef…", {"https://t.me/abcdef"});