Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

string_validation: Make check_stream_topic merely check, not alter.

Alex Vandiver58c8eebda29d
diff --git a/zerver/lib/addressee.py b/zerver/lib/addressee.py
index 207bf5cfd86..97f45cf455d 100644
--- a/zerver/lib/addressee.py
+++ b/zerver/lib/addressee.py
@@ -147,7 +147,8 @@ class Addressee:
@staticmethod
def for_stream(stream: Stream, topic: str) -> "Addressee":
- topic = check_stream_topic(topic)
+ topic = topic.strip()
+ check_stream_topic(topic)
return Addressee(
msg_type="stream",
stream=stream,
@@ -156,7 +157,8 @@ class Addressee:
@staticmethod
def for_stream_name(stream_name: str, topic: str) -> "Addressee":
- topic = check_stream_topic(topic)
+ topic = topic.strip()
+ check_stream_topic(topic)
return Addressee(
msg_type="stream",
stream_name=stream_name,
@@ -165,7 +167,8 @@ class Addressee:
@staticmethod
def for_stream_id(stream_id: int, topic: str) -> "Addressee":
- topic = check_stream_topic(topic)
+ topic = topic.strip()
+ check_stream_topic(topic)
return Addressee(
msg_type="stream",
stream_id=stream_id,
diff --git a/zerver/lib/string_validation.py b/zerver/lib/string_validation.py
index 7a404e17564..a6fc15cb9f6 100644
--- a/zerver/lib/string_validation.py
+++ b/zerver/lib/string_validation.py
@@ -22,14 +22,11 @@ def check_stream_name(stream_name: str) -> None:
)
-def check_stream_topic(topic: str) -> str:
- assert topic is not None
- topic = topic.strip()
- if topic == "":
+def check_stream_topic(topic: str) -> None:
+ if topic.strip() == "":
raise JsonableError(_("Topic can't be empty"))
for character in topic:
unicodeCategory = unicodedata.category(character)
if unicodeCategory in ["Cc", "Cs", "Cn"]:
raise JsonableError(_("Invalid characters in topic!"))
- return topic