# HG changeset patch # User Matt Mackall # Date 2012-02-17 19:53:19 # Node ID 6f236c8bdc01b4ddb7c6b3528284b0f1ba425d26 # Parent 33f702e52906aab4033039b5e31e7268bb95e80e 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 diff --git a/mercurial/graphmod.py b/mercurial/graphmod.py --- a/mercurial/graphmod.py +++ b/mercurial/graphmod.py @@ -18,7 +18,6 @@ Data depends on type. """ from mercurial.node import nullrev -import re CHANGESET = 'C' @@ -87,17 +86,14 @@ def colored(dag, repo): 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: