summary refs log tree commit diff
path: root/synapse/push
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-01-19 14:43:24 +0000
committerErik Johnston <erik@matrix.org>2016-01-19 14:43:24 +0000
commitd056a0a3d83933133f25f082b938d4115c803145 (patch)
tree947a8180b193afa16c91a660187d8713d0d9f638 /synapse/push
parentMerge pull request #477 from matrix-org/erikj/access_token_log (diff)
downloadsynapse-d056a0a3d83933133f25f082b938d4115c803145.tar.xz
Handle glob -> regex errors
Diffstat (limited to 'synapse/push')
-rw-r--r--synapse/push/push_rule_evaluator.py62
1 files changed, 33 insertions, 29 deletions
diff --git a/synapse/push/push_rule_evaluator.py b/synapse/push/push_rule_evaluator.py
index 379652c513..4654994d2d 100644
--- a/synapse/push/push_rule_evaluator.py
+++ b/synapse/push/push_rule_evaluator.py
@@ -258,40 +258,44 @@ def _glob_matches(glob, value, word_boundary=False):
     Returns:
         bool
     """
-    if IS_GLOB.search(glob):
-        r = re.escape(glob)
-
-        r = r.replace(r'\*', '.*?')
-        r = r.replace(r'\?', '.')
-
-        # handle [abc], [a-z] and [!a-z] style ranges.
-        r = GLOB_REGEX.sub(
-            lambda x: (
-                '[%s%s]' % (
-                    x.group(1) and '^' or '',
-                    x.group(2).replace(r'\\\-', '-')
-                )
-            ),
-            r,
-        )
-        if word_boundary:
+    try:
+        if IS_GLOB.search(glob):
+            r = re.escape(glob)
+
+            r = r.replace(r'\*', '.*?')
+            r = r.replace(r'\?', '.')
+
+            # handle [abc], [a-z] and [!a-z] style ranges.
+            r = GLOB_REGEX.sub(
+                lambda x: (
+                    '[%s%s]' % (
+                        x.group(1) and '^' or '',
+                        x.group(2).replace(r'\\\-', '-')
+                    )
+                ),
+                r,
+            )
+            if word_boundary:
+                r = r"\b%s\b" % (r,)
+                r = re.compile(r, flags=re.IGNORECASE)
+
+                return r.search(value)
+            else:
+                r = r + "$"
+                r = re.compile(r, flags=re.IGNORECASE)
+
+                return r.match(value)
+        elif word_boundary:
+            r = re.escape(glob)
             r = r"\b%s\b" % (r,)
             r = re.compile(r, flags=re.IGNORECASE)
 
             return r.search(value)
         else:
-            r = r + "$"
-            r = re.compile(r, flags=re.IGNORECASE)
-
-            return r.match(value)
-    elif word_boundary:
-        r = re.escape(glob)
-        r = r"\b%s\b" % (r,)
-        r = re.compile(r, flags=re.IGNORECASE)
-
-        return r.search(value)
-    else:
-        return value.lower() == glob.lower()
+            return value.lower() == glob.lower()
+    except re.error:
+        logger.warn("Failed to parse glob to regex: %r", glob)
+        return False
 
 
 def _flatten_dict(d, prefix=[], result={}):