zcommand: Raise error when command doesn't begin with a slash.

This commit is contained in:
Rhea Parekh
2018-06-21 22:53:35 +05:30
committed by showell
parent b22d266667
commit fdef1d8d91
2 changed files with 7 additions and 1 deletions

View File

@@ -6,7 +6,9 @@ from zerver.lib.actions import do_set_user_display_setting
from zerver.lib.exceptions import JsonableError
def process_zcommands(content: str, user_profile: UserProfile) -> Dict[str, Any]:
command = content.replace('/', '')
if not content.startswith('/'):
raise JsonableError(_('There should be a leading slash in the zcommand.'))
command = content[1:]
if command == 'ping':
ret = dict() # type: Dict[str, Any]

View File

@@ -13,6 +13,10 @@ class ZcommandTest(ZulipTestCase):
result = self.client_post("/json/zcommand", payload)
self.assert_json_error(result, "No such command: boil-ocean")
payload = dict(command="boil-ocean")
result = self.client_post("/json/zcommand", payload)
self.assert_json_error(result, "There should be a leading slash in the zcommand.")
def test_ping_zcommand(self) -> None:
self.login(self.example_email("hamlet"))