mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 14:35:27 +00:00
string_validation: Make check_stream_topic merely check, not alter.
Co-authored-by: Shlok Patel <shlokcpatel2001@gmail.com>
This commit is contained in:
@@ -147,7 +147,8 @@ class Addressee:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def for_stream(stream: Stream, topic: str) -> "Addressee":
|
def for_stream(stream: Stream, topic: str) -> "Addressee":
|
||||||
topic = check_stream_topic(topic)
|
topic = topic.strip()
|
||||||
|
check_stream_topic(topic)
|
||||||
return Addressee(
|
return Addressee(
|
||||||
msg_type="stream",
|
msg_type="stream",
|
||||||
stream=stream,
|
stream=stream,
|
||||||
@@ -156,7 +157,8 @@ class Addressee:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def for_stream_name(stream_name: str, topic: str) -> "Addressee":
|
def for_stream_name(stream_name: str, topic: str) -> "Addressee":
|
||||||
topic = check_stream_topic(topic)
|
topic = topic.strip()
|
||||||
|
check_stream_topic(topic)
|
||||||
return Addressee(
|
return Addressee(
|
||||||
msg_type="stream",
|
msg_type="stream",
|
||||||
stream_name=stream_name,
|
stream_name=stream_name,
|
||||||
@@ -165,7 +167,8 @@ class Addressee:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def for_stream_id(stream_id: int, topic: str) -> "Addressee":
|
def for_stream_id(stream_id: int, topic: str) -> "Addressee":
|
||||||
topic = check_stream_topic(topic)
|
topic = topic.strip()
|
||||||
|
check_stream_topic(topic)
|
||||||
return Addressee(
|
return Addressee(
|
||||||
msg_type="stream",
|
msg_type="stream",
|
||||||
stream_id=stream_id,
|
stream_id=stream_id,
|
||||||
|
|||||||
@@ -22,14 +22,11 @@ def check_stream_name(stream_name: str) -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def check_stream_topic(topic: str) -> str:
|
def check_stream_topic(topic: str) -> None:
|
||||||
assert topic is not None
|
if topic.strip() == "":
|
||||||
topic = topic.strip()
|
|
||||||
if topic == "":
|
|
||||||
raise JsonableError(_("Topic can't be empty"))
|
raise JsonableError(_("Topic can't be empty"))
|
||||||
|
|
||||||
for character in topic:
|
for character in topic:
|
||||||
unicodeCategory = unicodedata.category(character)
|
unicodeCategory = unicodedata.category(character)
|
||||||
if unicodeCategory in ["Cc", "Cs", "Cn"]:
|
if unicodeCategory in ["Cc", "Cs", "Cn"]:
|
||||||
raise JsonableError(_("Invalid characters in topic!"))
|
raise JsonableError(_("Invalid characters in topic!"))
|
||||||
return topic
|
|
||||||
|
|||||||
Reference in New Issue
Block a user