src/mercurialserver/ruleset.py
branchdebian
changeset 115 731a72b742db
parent 109 72100d3ed1bd
child 237 d30f3f312ece
--- a/src/mercurialserver/ruleset.py	Thu May 28 10:43:30 2009 +0100
+++ b/src/mercurialserver/ruleset.py	Tue Oct 13 15:30:03 2009 +0100
@@ -12,28 +12,10 @@
 
 allowedchars = "A-Za-z0-9_-"
 
-goodpathre = re.compile("([%s]+/)*[%s]+$" % (allowedchars, allowedchars))
-def goodpath(path):
-    return goodpathre.match(path) is not None
-
-goodglobre = re.compile("[*/%s]+$" % allowedchars)
-
-def goodglob(pattern):
-    return goodglobre.match(pattern) is not None
-
-# Don't put anything except *A-Za-z0-9_- in rule globs or   
-# it will match nothing.  No regexp metachars, not even .
-# We may fix this later.
 def globmatcher(pattern):
-    if not goodglob(pattern):
-        #fail("Bad glob pattern in auth config: %s" % pattern)
-        # FIXME: report it somehow
-        return lambda x: False
-    # Substitution cunning so ** can be different from *
-    pattern = pattern.replace("*", "[]")
-    pattern = pattern.replace("[][]", "[/%s]*" % allowedchars)
-    pattern = pattern.replace("[]", "[%s]*" % allowedchars)
-    rex = re.compile(pattern + "$")
+    p = "[^/]*".join(re.escape(c) for c in pattern.split("*"))
+    # ** means "match recursively" ie "ignore directories"
+    rex = re.compile(p.replace("[^/]*[^/]*", ".*") + "$")
     # None matches everything
     return lambda x: x is None or rex.match(x) is not None