summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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: