summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2018-10-18 14:21:09 +0100
committerErik Johnston <erik@matrix.org>2018-10-19 10:22:45 +0100
commit9fafdfa97d87006177d13d4b80aeebfc4ded4bee (patch)
treed50809b3cd0d59fd251df2d5839265ca7bb8a6a8 /synapse
parentNewsfile (diff)
downloadsynapse-9fafdfa97d87006177d13d4b80aeebfc4ded4bee.tar.xz
Anchor returned regex to start and end of string
Diffstat (limited to 'synapse')
-rw-r--r--synapse/util/__init__.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/synapse/util/__init__.py b/synapse/util/__init__.py
index 163e4b35ff..0ae7e2ef3b 100644
--- a/synapse/util/__init__.py
+++ b/synapse/util/__init__.py
@@ -142,7 +142,9 @@ def log_failure(failure, msg, consumeErrors=True):
 
 
 def glob_to_regex(glob):
-    """Converts a glob to a compiled regex object
+    """Converts a glob to a compiled regex object.
+
+    The regex is anchored at the beginning and end of the string.
 
     Args:
         glob (str)
@@ -158,4 +160,6 @@ def glob_to_regex(glob):
             res = res + '.'
         else:
             res = res + re.escape(c)
-    return re.compile(res + "\\Z", re.IGNORECASE)
+
+    # \A anchors at start of string, \Z at end of string
+    return re.compile(r"\A" + res + r"\Z", re.IGNORECASE)