summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorDavid Baker <dave@matrix.org>2015-01-23 11:19:02 +0000
committerDavid Baker <dave@matrix.org>2015-01-23 11:19:02 +0000
commit49fe31792bc0cf709248e592baefb8f34606236a (patch)
tree26a3c5ea199bc3ae9d537eecfe5b128ad8402391 /synapse
parentright super() param (diff)
downloadsynapse-49fe31792bc0cf709248e592baefb8f34606236a.tar.xz
Add slightly pedantic trailing slash error.
Diffstat (limited to 'synapse')
-rw-r--r--synapse/api/errors.py7
-rw-r--r--synapse/rest/client/v1/push_rule.py15
2 files changed, 19 insertions, 3 deletions
diff --git a/synapse/api/errors.py b/synapse/api/errors.py
index 4f59e1742c..5872e82d0f 100644
--- a/synapse/api/errors.py
+++ b/synapse/api/errors.py
@@ -88,9 +88,14 @@ class UnrecognizedRequestError(SynapseError):
     def __init__(self, *args, **kwargs):
         if "errcode" not in kwargs:
             kwargs["errcode"] = Codes.UNRECOGNIZED
+        message = None
+        if len(args) == 0:
+            message = "Unrecognized request"
+        else:
+            message = args[0]
         super(UnrecognizedRequestError, self).__init__(
             400,
-            "Unrecognized request",
+            message,
             **kwargs
         )
 
diff --git a/synapse/rest/client/v1/push_rule.py b/synapse/rest/client/v1/push_rule.py
index 77a0772479..6f108431b2 100644
--- a/synapse/rest/client/v1/push_rule.py
+++ b/synapse/rest/client/v1/push_rule.py
@@ -32,6 +32,8 @@ class PushRuleRestServlet(RestServlet):
         'override': 4
     }
     PRIORITY_CLASS_INVERSE_MAP = {v: k for k,v in PRIORITY_CLASS_MAP.items()}
+    SLIGHTLY_PEDANTIC_TRAILING_SLASH_ERROR =\
+        "Unrecognised request: You probably wanted a trailing slash"
 
     def rule_spec_from_path(self, path):
         if len(path) < 2:
@@ -211,10 +213,14 @@ class PushRuleRestServlet(RestServlet):
                 rulearray.append(template_rule)
 
         path = request.postpath[1:]
+
         if path == []:
-            defer.returnValue((200, rules))
+            # we're a reference impl: pedantry is our job.
+            raise UnrecognizedRequestError(PushRuleRestServlet.SLIGHTLY_PEDANTIC_TRAILING_SLASH_ERROR)
 
-        if path[0] == 'global':
+        if path[0] == '':
+            defer.returnValue((200, rules))
+        elif path[0] == 'global':
             path = path[1:]
             result = _filter_ruleset_with_path(rules['global'], path)
             defer.returnValue((200, result))
@@ -255,12 +261,17 @@ def _instance_handle_from_conditions(conditions):
 
 def _filter_ruleset_with_path(ruleset, path):
     if path == []:
+        raise UnrecognizedRequestError(PushRuleRestServlet.SLIGHTLY_PEDANTIC_TRAILING_SLASH_ERROR)
+
+    if path[0] == '':
         return ruleset
     template_kind = path[0]
     if template_kind not in ruleset:
         raise UnrecognizedRequestError()
     path = path[1:]
     if path == []:
+        raise UnrecognizedRequestError(PushRuleRestServlet.SLIGHTLY_PEDANTIC_TRAILING_SLASH_ERROR)
+    if path[0] == '':
         return ruleset[template_kind]
     rule_id = path[0]
     for r in ruleset[template_kind]: