snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
This commit is contained in:
65
zerver/lib/string_validation.py
Normal file
65
zerver/lib/string_validation.py
Normal file
@@ -0,0 +1,65 @@
|
||||
import unicodedata
|
||||
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from zerver.lib.exceptions import JsonableError
|
||||
from zerver.models import Stream
|
||||
|
||||
# There are 66 Unicode non-characters; see
|
||||
# https://www.unicode.org/faq/private_use.html#nonchar4
|
||||
unicode_non_chars = {
|
||||
chr(x)
|
||||
for r in [
|
||||
range(0xFDD0, 0xFDF0), # FDD0 through FDEF, inclusive
|
||||
range(0xFFFE, 0x110000, 0x10000), # 0xFFFE, 0x1FFFE, ... 0x10FFFE inclusive
|
||||
range(0xFFFF, 0x110000, 0x10000), # 0xFFFF, 0x1FFFF, ... 0x10FFFF inclusive
|
||||
]
|
||||
for x in r
|
||||
}
|
||||
|
||||
|
||||
def is_character_printable(char: str) -> bool:
|
||||
unicode_category = unicodedata.category(char)
|
||||
if (unicode_category in ["Cc", "Cs"]) or char in unicode_non_chars:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def check_string_is_printable(var: str) -> int | None:
|
||||
# Return position (1-indexed!) of the character which is not
|
||||
# printable, None if no such character is present.
|
||||
for i, char in enumerate(var):
|
||||
if not is_character_printable(char):
|
||||
return i + 1
|
||||
return None
|
||||
|
||||
|
||||
def check_stream_name(stream_name: str) -> None:
|
||||
if stream_name.strip() == "":
|
||||
raise JsonableError(_("Channel name can't be empty."))
|
||||
|
||||
if len(stream_name) > Stream.MAX_NAME_LENGTH:
|
||||
raise JsonableError(
|
||||
_("Channel name too long (limit: {max_length} characters).").format(
|
||||
max_length=Stream.MAX_NAME_LENGTH
|
||||
)
|
||||
)
|
||||
|
||||
invalid_character_pos = check_string_is_printable(stream_name)
|
||||
if invalid_character_pos is not None:
|
||||
raise JsonableError(
|
||||
_("Invalid character in channel name, at position {position}.").format(
|
||||
position=invalid_character_pos
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def check_stream_topic(topic_name: str) -> None:
|
||||
invalid_character_pos = check_string_is_printable(topic_name)
|
||||
if invalid_character_pos is not None:
|
||||
raise JsonableError(
|
||||
_("Invalid character in topic, at position {position}!").format(
|
||||
position=invalid_character_pos
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user