summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pym/portage/util.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/pym/portage/util.py b/pym/portage/util.py
index 6f11934e8..9f7c92828 100644
--- a/pym/portage/util.py
+++ b/pym/portage/util.py
@@ -16,6 +16,7 @@ import commands
import codecs
import errno
import logging
+import re
import shlex
import stat
import string
@@ -379,6 +380,8 @@ class _tolerant_shlex(shlex.shlex):
(self.infile, str(e)), noiselevel=-1)
return (newfile, StringIO())
+_invalid_var_name_re = re.compile(r'^\d|\W')
+
def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True):
if isinstance(expand, dict):
# Some existing variable definitions have been
@@ -462,6 +465,16 @@ def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True):
return mykeys
key = _unicode_decode(key)
val = _unicode_decode(val)
+
+ if _invalid_var_name_re.search(key) is not None:
+ if not tolerant:
+ raise Exception(_(
+ "ParseError: Invalid variable name '%s': line %s") % \
+ (key, lex.lineno - 1))
+ writemsg(_("!!! Invalid variable name '%s': line %s in %s\n") \
+ % (key, lex.lineno - 1, mycfg), noiselevel=-1)
+ continue
+
if expand:
mykeys[key] = varexpand(val, expand_map)
expand_map[key] = mykeys[key]