Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
url_encoding: Use user name instead of email in personal_narrow_url.
Sahil Batra2a8b7412ffc9
diff --git a/zerver/lib/url_encoding.py b/zerver/lib/url_encoding.pyindex ffb60ab7e34..a217e35ec99 100644--- a/zerver/lib/url_encoding.py+++ b/zerver/lib/url_encoding.py@@ -1,7 +1,8 @@-from email.headerregistry import Addressfrom typing import Any, Dict, Listfrom urllib.parse import quote, urlsplit+import re2+from zerver.lib.topic import get_topic_from_message_infofrom zerver.models import Realm, Stream, UserProfile@@ -21,8 +22,8 @@ def encode_stream(stream_id: int, stream_name: str) -> str:def personal_narrow_url(realm: Realm, sender: UserProfile) -> str:base_url = f"{realm.uri}/#narrow/pm-with/"- email_user = Address(addr_spec=sender.email).username.lower()- pm_slug = str(sender.id) + "-" + hash_util_encode(email_user)+ encoded_user_name = re2.sub(r'[ "%\/<>`\p{C}]+', "-", sender.full_name)+ pm_slug = str(sender.id) + "-" + encoded_user_namereturn base_url + pm_slugdiff --git a/zerver/tests/test_email_notifications.py b/zerver/tests/test_email_notifications.pyindex 5e9e6b2e669..8c0e9712eec 100644--- a/zerver/tests/test_email_notifications.py+++ b/zerver/tests/test_email_notifications.py@@ -1183,6 +1183,21 @@ class TestMissedMessages(ZulipTestCase):msg_id, verify_body_include, email_subject, send_as_user=False, verify_html_body=True)+ def test_pm_link_in_missed_message_header(self) -> None:+ cordelia = self.example_user("cordelia")+ msg_id = self.send_personal_message(+ cordelia,+ self.example_user("hamlet"),+ "Let's test PM link in email notifications",+ )++ encoded_name = "Cordelia,-Lear's-daughter"+ verify_body_include = [+ f"view it in Zulip Dev Zulip: http://zulip.testserver/#narrow/pm-with/{cordelia.id}-{encoded_name}"+ ]+ email_subject = "PMs with Cordelia, Lear's daughter"+ self._test_cases(msg_id, verify_body_include, email_subject, send_as_user=False)+def test_sender_name_in_missed_message(self) -> None:hamlet = self.example_user("hamlet")msg_id_1 = self.send_stream_message(