Atom: handle invalid */foo-version wildcard
authorZac Medico <zmedico@gentoo.org>
Fri, 24 May 2013 18:02:22 +0000 (11:02 -0700)
committerZac Medico <zmedico@gentoo.org>
Fri, 24 May 2013 18:02:22 +0000 (11:02 -0700)
Before, a wildcard atom could be treated as valid even though it
specified a version without an operator, as reported at here:

https://forums.gentoo.org/viewtopic-p-7314746.html#7314746

pym/portage/dep/__init__.py
pym/portage/tests/dep/test_isvalidatom.py

index 6f3b3573953a86c02c66f91da4ae894fc863d131..7776f895838232e73807d6870d9c36dc1830d865 100644 (file)
@@ -29,7 +29,7 @@ from portage.eapi import _get_eapi_attrs
 from portage.exception import InvalidAtom, InvalidData, InvalidDependString
 from portage.localization import _
 from portage.versions import catpkgsplit, catsplit, \
-       vercmp, ververify, _cp, _cpv, _pkg_str, _slot, _unknown_repo
+       vercmp, ververify, _cp, _cpv, _pkg_str, _slot, _unknown_repo, _vr
 import portage.cache.mappings
 
 if sys.hexversion >= 0x3000000:
@@ -121,7 +121,7 @@ def _get_atom_wildcard_re(eapi_attrs):
                pkg_re = r'[\w+*][\w+*-]*?'
 
        atom_re = re.compile(r'((?P<simple>(' +
-               _extended_cat + r')/(' + pkg_re + r'))' + \
+               _extended_cat + r')/(' + pkg_re + r'(-' + _vr + ')?))' + \
                '|(?P<star>=((' + _extended_cat + r')/(' + pkg_re + r'))-(?P<version>\*\w+\*)))' + \
                '(:(?P<slot>' + _slot_loose + r'))?(' +
                _repo_separator + r'(?P<repo>' + _repo_name + r'))?$', re.UNICODE)
@@ -1243,6 +1243,8 @@ class Atom(_unicode):
                                else:
                                        op = None
                                        cpv = cp = m.group('simple')
+                                       if m.group(atom_re.groupindex['simple'] + 3) is not None:
+                                               raise InvalidAtom(self)
                                if cpv.find("**") != -1:
                                        raise InvalidAtom(self)
                                slot = m.group('slot')
index 6b0566da6789f7869e1c37ce6e3e3e9bda49218b..67ba6039835adfe455ff7b9113c6bd43b141e2d4 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2006-2010 Gentoo Foundation
+# Copyright 2006-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 from portage.tests import TestCase
@@ -143,6 +143,9 @@ class IsValidAtom(TestCase):
                        IsValidAtomTestCase("virtual/ffmpeg:*", True),
                        IsValidAtomTestCase("virtual/ffmpeg:0*", False),
                        IsValidAtomTestCase("virtual/ffmpeg:0", True),
+
+                       # Wildcard atoms
+                       IsValidAtomTestCase("*/portage-2.1", False, allow_wildcard=True),
                )
 
                for test_case in test_cases: