Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #331 from matrix-org/rav/500_on_missing_sigil
Browse files Browse the repository at this point in the history
Fix a 500 error resulting from empty room_ids
  • Loading branch information
richvdh committed Oct 27, 2015
2 parents 3f0a57e + f69a5c9 commit d0b1968
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion synapse/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __deepcopy__(self, memo):
@classmethod
def from_string(cls, s):
"""Parse the string given by 's' into a structure object."""
if s[0] != cls.SIGIL:
if len(s) < 1 or s[0] != cls.SIGIL:
raise SynapseError(400, "Expected %s string to start with '%s'" % (
cls.__name__, cls.SIGIL,
))
Expand Down
9 changes: 7 additions & 2 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,26 @@

from tests import unittest

from synapse.api.errors import SynapseError
from synapse.server import BaseHomeServer
from synapse.types import UserID, RoomAlias

mock_homeserver = BaseHomeServer(hostname="my.domain")

class UserIDTestCase(unittest.TestCase):

class UserIDTestCase(unittest.TestCase):
def test_parse(self):
user = UserID.from_string("@1234abcd:my.domain")

self.assertEquals("1234abcd", user.localpart)
self.assertEquals("my.domain", user.domain)
self.assertEquals(True, mock_homeserver.is_mine(user))

def test_pase_empty(self):
with self.assertRaises(SynapseError):
UserID.from_string("")


def test_build(self):
user = UserID("5678efgh", "my.domain")

Expand All @@ -44,7 +50,6 @@ def test_compare(self):


class RoomAliasTestCase(unittest.TestCase):

def test_parse(self):
room = RoomAlias.from_string("#channel:my.domain")

Expand Down

0 comments on commit d0b1968

Please sign in to comment.