From 86ea3834dcb002bbe9e095771aedbbc85f539748 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sat, 2 Oct 2010 10:00:18 -0700 Subject: Bug #339402 - Ensure valid repo name. --- pym/portage/repository/config.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pym/portage/repository/config.py b/pym/portage/repository/config.py index acaec70bb..0e2507a82 100644 --- a/pym/portage/repository/config.py +++ b/pym/portage/repository/config.py @@ -3,6 +3,7 @@ import codecs import logging +import re try: from configparser import SafeConfigParser, ParsingError @@ -16,6 +17,8 @@ from portage.localization import _ from portage import _unicode_encode from portage import _encodings +_repo_name_sub_re = re.compile(r'[^\w-]') + class RepoConfig(object): """Stores config of one repository""" @@ -72,7 +75,21 @@ class RepoConfig(object): missing = True if self.location is not None: name, missing = self._read_repo_name(self.location) + # We must ensure that the name conforms to PMS 3.1.5 + # in order to avoid InvalidAtom exceptions when we + # use it to generate atoms. + name = _repo_name_sub_re.sub(' ', name.strip()) name = '-'.join(name.split()) + name = name.lstrip('-') + if not name: + # name only contains invalid characters + name = "x-" + os.path.basename(self.location) + name = _repo_name_sub_re.sub(' ', name.strip()) + name = '-'.join(name.split()) + name = name.lstrip('-') + # If basename only contains whitespace then the + # end result is name = 'x'. + elif name == "DEFAULT": missing = False self.name = name -- cgit v1.2.3-1-g7c22