summaryrefslogtreecommitdiffstats
path: root/pym
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-09-08 08:07:03 +0000
committerZac Medico <zmedico@gentoo.org>2009-09-08 08:07:03 +0000
commit817594390e64888da26950477ca99bc334eeeed4 (patch)
treec80aa73a93341d341754b1c2f55d2ddf16b4077a /pym
parentb0526977815637c3f44bb1f11d6e700a6250588e (diff)
downloadportage-817594390e64888da26950477ca99bc334eeeed4.tar.gz
portage-817594390e64888da26950477ca99bc334eeeed4.tar.bz2
portage-817594390e64888da26950477ca99bc334eeeed4.zip
Fix isvalidatom() to check the 'must not end in' clause from PMS 2.1.2.
Thanks to Marat Radchenko <marat@slonopotamus.org> for this patch. svn path=/main/trunk/; revision=14216
Diffstat (limited to 'pym')
-rw-r--r--pym/portage/dep.py9
-rw-r--r--pym/portage/tests/dep/test_isvalidatom.py13
2 files changed, 16 insertions, 6 deletions
diff --git a/pym/portage/dep.py b/pym/portage/dep.py
index 0bc9fe647..81364f344 100644
--- a/pym/portage/dep.py
+++ b/pym/portage/dep.py
@@ -840,8 +840,9 @@ _cat = r'[A-Za-z0-9+_][A-Za-z0-9+_.-]*'
# 2.1.2 A package name may contain any of the characters [A-Za-z0-9+_-].
# It must not begin with a hyphen,
# and must not end in a hyphen followed by one or more digits.
-# FIXME: this regex doesn't check 'must not end in' clause.
-_pkg = r'[A-Za-z0-9+_][A-Za-z0-9+_-]*'
+_pkg = r'([A-Za-z+_]+[A-Za-z0-9+_]+|([A-Za-z0-9+_](' + \
+ '[A-Za-z0-9+_-]?|' + \
+ '([A-Za-z0-9+_-]*(([A-Za-z0-9+_][A-Za-z+_-]+)|([A-Za-z+_][A-Za-z0-9+_]+))))))'
# 2.1.3 A slot name may contain any of the characters [A-Za-z0-9+_.-].
# It must not begin with a hyphen or a dot.
@@ -852,7 +853,7 @@ _op = r'([=><~]|([><]=))'
_cp = _cat + '/' + _pkg
_cpv = _cp + '-' + _version
-_atom = re.compile(r'^(' +
+_atom_re = re.compile(r'^(' +
'(' + _op + _cpv + _slot + _use + ')|' +
'(=' + _cpv + r'\*' + _slot + _use + ')|' +
'(' + _cp + _slot + _use + ')' +
@@ -887,7 +888,7 @@ def isvalidatom(atom, allow_blockers=False):
atom = atom[2:]
else:
atom = atom[1:]
- if _atom.match(atom) is None:
+ if _atom_re.match(atom) is None:
return False
try:
use = dep_getusedeps(atom)
diff --git a/pym/portage/tests/dep/test_isvalidatom.py b/pym/portage/tests/dep/test_isvalidatom.py
index e74ec8ff5..7797025f9 100644
--- a/pym/portage/tests/dep/test_isvalidatom.py
+++ b/pym/portage/tests/dep/test_isvalidatom.py
@@ -62,13 +62,22 @@ class IsValidAtom(TestCase):
( ">=null/portage-2.1", True ),
( "~null/portage-2.1", True ),
( "=null/portage-2.1*", True ),
- ( "=foo/bar-123-1", True ),
- ( "=foo/bar-123-1-r1", True ),
+
+ # These are invalid because pkg name must not end in hyphen
+ # followed by numbers
+ ( "=foo/bar-123-1", False ),
+ ( "=foo/bar-123-1-r1", False ),
+ ( "foo/bar-1", False ),
+
( "=foo/bar--baz-1-r1", True ),
( "=foo/bar-baz--1-r1", True ),
( "=foo/bar-baz---1-r1", True ),
( "=foo/bar-baz---1", True ),
( "=foo/bar-baz-1--r1", False ),
+ ( "games-strategy/ufo2000", True ),
+ ( "~games-strategy/ufo2000-0.1", True ),
+ ( "=media-libs/x264-20060810", True ),
+ ( "foo/b", True ),
]
for test in tests: