summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard van der Hoff <github@rvanderhoff.org.uk>2015-10-27 15:20:57 +0000
committerRichard van der Hoff <github@rvanderhoff.org.uk>2015-10-27 15:20:57 +0000
commitd0b1968a4cfcf4289d2b519fa141af2495431a4b (patch)
tree24915683079b7031654130f3aa1985f84b5b6a7f
parentMerge pull request #328 from matrix-org/erikj/search (diff)
parentFix a 500 error resulting from empty room_ids (diff)
downloadsynapse-d0b1968a4cfcf4289d2b519fa141af2495431a4b.tar.xz
Merge pull request #331 from matrix-org/rav/500_on_missing_sigil
Fix a 500 error resulting from empty room_ids
Diffstat (limited to '')
-rw-r--r--synapse/types.py2
-rw-r--r--tests/test_types.py9
2 files changed, 8 insertions, 3 deletions
diff --git a/synapse/types.py b/synapse/types.py
index 9cffc33d27..8c51e00e8a 100644
--- a/synapse/types.py
+++ b/synapse/types.py
@@ -47,7 +47,7 @@ class DomainSpecificString(
     @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,
             ))
diff --git a/tests/test_types.py b/tests/test_types.py
index b29a8415b1..495cd20f02 100644
--- a/tests/test_types.py
+++ b/tests/test_types.py
@@ -15,13 +15,14 @@
 
 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")
 
@@ -29,6 +30,11 @@ class UserIDTestCase(unittest.TestCase):
         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")
 
@@ -44,7 +50,6 @@ class UserIDTestCase(unittest.TestCase):
 
 
 class RoomAliasTestCase(unittest.TestCase):
-
     def test_parse(self):
         room = RoomAlias.from_string("#channel:my.domain")