changeset 16131:6f236c8bdc01

graphmod: rewrite graph config validation Our goal is not to strictly disallow _invalid_ input, simply disallow _hostile_ input. Avoid using re Avoid creating empty dicts when no branch parameters are recognized
author Matt Mackall <mpm@selenic.com>
date Fri, 17 Feb 2012 13:53:19 -0600
parents 33f702e52906
children 41fc1e078d68
files mercurial/graphmod.py
diffstat 1 files changed, 7 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/graphmod.py	Sun Jan 22 19:47:03 2012 +0700
+++ b/mercurial/graphmod.py	Fri Feb 17 13:53:19 2012 -0600
@@ -18,7 +18,6 @@
 """
 
 from mercurial.node import nullrev
-import re
 
 CHANGESET = 'C'
 
@@ -87,17 +86,14 @@
     config = {}
 
     for key, val in repo.ui.configitems('graph'):
-        if '.' not in key:
-            continue
-        branch, setting = key.rsplit('.', 1)
-        gdict = config.setdefault(branch, {})
+        if '.' in key:
+            branch, setting = key.rsplit('.', 1)
+            # Validation
+            if setting == "width" and val.isdigit():
+                config.setdefault(branch, {})[setting] = val
+            elif setting == "color" and val.isalnum():
+                config.setdefault(branch, {})[setting] = val
 
-        # Validation
-        if ((setting == "width" and val.isdigit() and 0 < int(val) < 30) or
-                (setting == "color" and re.match('^[0-9a-fA-F]{6}$', val))):
-            gdict[setting] = val
-        else:
-            continue
 
     for (cur, type, data, parents) in dag: