summary refs log tree commit diff
path: root/synapse/appservice
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2015-02-27 10:44:32 +0000
committerKegan Dougal <kegan@matrix.org>2015-02-27 10:44:32 +0000
commit16b90764adb8f2ab49b1853855d0fb739b79d245 (patch)
treefcf1b55345fabed793bb0273e9806467a7d5f594 /synapse/appservice
parentSYWEB-278 Don't allow rules with no rule_id. (diff)
downloadsynapse-16b90764adb8f2ab49b1853855d0fb739b79d245.tar.xz
Convert expected format for AS regex to include exclusivity.
Previously you just specified the regex as a string, now it expects a JSON
object with a 'regex' key and an 'exclusive' boolean, as per spec.
Diffstat (limited to 'synapse/appservice')
-rw-r--r--synapse/appservice/__init__.py26
1 files changed, 19 insertions, 7 deletions
diff --git a/synapse/appservice/__init__.py b/synapse/appservice/__init__.py
index 381b4cfc4a..b5e7ac16ba 100644
--- a/synapse/appservice/__init__.py
+++ b/synapse/appservice/__init__.py
@@ -46,19 +46,31 @@ class ApplicationService(object):
     def _check_namespaces(self, namespaces):
         # Sanity check that it is of the form:
         # {
-        #   users: ["regex",...],
-        #   aliases: ["regex",...],
-        #   rooms: ["regex",...],
+        #   users: [ {regex: "[A-z]+.*", exclusive: true}, ...],
+        #   aliases: [ {regex: "[A-z]+.*", exclusive: true}, ...],
+        #   rooms: [ {regex: "[A-z]+.*", exclusive: true}, ...],
         # }
         if not namespaces:
             return None
 
         for ns in ApplicationService.NS_LIST:
+            if ns not in namespaces:
+                namespaces[ns] = []
+                continue
+
             if type(namespaces[ns]) != list:
-                raise ValueError("Bad namespace value for '%s'", ns)
-            for regex in namespaces[ns]:
-                if not isinstance(regex, basestring):
-                    raise ValueError("Expected string regex for ns '%s'", ns)
+                raise ValueError("Bad namespace value for '%s'" % ns)
+            for regex_obj in namespaces[ns]:
+                if not isinstance(regex_obj, dict):
+                    raise ValueError("Expected dict regex for ns '%s'" % ns)
+                if not isinstance(regex_obj.get("exclusive"), bool):
+                    raise ValueError(
+                        "Expected bool for 'exclusive' in ns '%s'" % ns
+                    )
+                if not isinstance(regex_obj.get("regex"), basestring):
+                    raise ValueError(
+                        "Expected string for 'regex' in ns '%s'" % ns
+                    )
         return namespaces
 
     def _matches_regex(self, test_string, namespace_key):