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
--- 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: