commit:     475f40440d38d19e190563b92725e8cfd6bae522
Author:     Brian Harring <ferringb <AT> gmail <DOT> com>
AuthorDate: Fri Nov 21 19:26:08 2025 +0000
Commit:     Brian Harring <ferringb <AT> gmail <DOT> com>
CommitDate: Fri Nov 21 19:33:46 2025 +0000
URL:        
https://gitweb.gentoo.org/proj/pkgcore/pkgcore.git/commit/?id=475f4044

fix: update categories rules to match PMS

Bug #453.

That code's pre spec existance, and back when I was trying to
sell people on N>1 depth categories.

PMS allows some weird stuff, but add explicit tests for this.

Signed-off-by: Brian Harring <ferringb <AT> gmail.com>

 src/pkgcore/ebuild/cpv.py |  6 +++---
 tests/ebuild/test_cpv.py  | 21 ++++++++++++++-------
 2 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/src/pkgcore/ebuild/cpv.py b/src/pkgcore/ebuild/cpv.py
index 39a0339e..263a505d 100644
--- a/src/pkgcore/ebuild/cpv.py
+++ b/src/pkgcore/ebuild/cpv.py
@@ -21,9 +21,9 @@ demand_compile_regexp(
     r"^(?:\d+)(?:\.\d+)*[a-zA-Z]?(?:_(p(?:re)?|beta|alpha|rc)\d*)*$",
 )
 
-demand_compile_regexp(
-    "isvalid_cat_re", r"^(?:[a-zA-Z0-9][-a-zA-Z0-9+._]*(?:/(?!$))?)+$"
-)
+# see https://github.com/pkgcore/pkgcore/issues/453 for why this regex 
underscores
+# PMS Category names regex is directly replicated below.
+demand_compile_regexp("isvalid_cat_re", r"^(?:[A-Za-z0-9_][A-Za-z0-9+_-]*)$")
 
 # empty string is fine, means a -- was encounter.
 demand_compile_regexp("_pkg_re", r"^[a-zA-Z0-9+_]+$")

diff --git a/tests/ebuild/test_cpv.py b/tests/ebuild/test_cpv.py
index ae7d8026..52991f23 100644
--- a/tests/ebuild/test_cpv.py
+++ b/tests/ebuild/test_cpv.py
@@ -1,6 +1,7 @@
 from random import shuffle
 
 import pytest
+
 from pkgcore.ebuild import cpv
 
 
@@ -20,19 +21,25 @@ def generate_misc_sufs():
 
 class TestCPV:
     good_cats = (
+        # see https://github.com/pkgcore/pkgcore/issues/453 .  PMS regex broke 
from pre spec allowing some weird stuff.
         "dev-util",
         "dev+",
-        "dev-util+",
-        "DEV-UTIL",
+        "DEV-UTIL+",
         "aaa0",
         "aaa-0",
-        "multi/depth",
-        "cross-dev_idiot.hacks-suck",
-        "a",
-        "foo---",
         "multi--hyphen",
+        "_dev",
+        "_",  # yep, that's legal.
+    )
+    bad_cats = (
+        "",
+        "-",
+        "+",
+        "dev-util ",
+        "multi/blah/depth",
+        "multi//depth",
+        "reject.a",
     )
-    bad_cats = (".util", "_dev", "", "dev-util ", "multi//depth")
     good_pkgs = (
         "diffball",
         "a9",

Reply via email to