Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Changelog
- Fix type hint for ``BasePurlType.allowed_qualifiers``
https://github.com/package-url/packageurl-python/pull/213

- Fix substring matching on the ``cpan`` and ``mlflow`` type checks
https://github.com/package-url/packageurl-python/pull/232

0.17.6 (2025-11-24)
-------------------

Expand Down
4 changes: 2 additions & 2 deletions src/packageurl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def normalize_namespace(
"hex",
):
namespace_str = namespace_str.lower()
if ptype and ptype in ("cpan"):
if ptype == "cpan":
namespace_str = namespace_str.upper()
segments = [seg for seg in namespace_str.split("/") if seg.strip()]
segments_quoted = map(get_quoter(encode), segments)
Expand Down Expand Up @@ -189,7 +189,7 @@ def normalize_name(
quoter = get_quoter(encode)
name_str = quoter(name_str)
name_str = name_str.strip().strip("/")
if ptype and ptype in ("mlflow"):
if ptype == "mlflow":
return normalize_mlflow_name(name_str, qualifiers)
if ptype in (
"bitbucket",
Expand Down
22 changes: 22 additions & 0 deletions tests/test_packageurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

from packageurl import PackageURL
from packageurl import normalize
from packageurl import normalize_name
from packageurl import normalize_namespace
from packageurl import normalize_qualifiers


Expand Down Expand Up @@ -388,3 +390,23 @@ def test_no_encoding_to_string():
p.to_string(encode=False)
== "pkg:nuget/an:odd:space/libiconv: character set conversion library@1.9?package-id=e11a609df352e292"
)


def test_cpan_namespace_uppercasing_is_not_applied_to_substring_types() -> None:
assert normalize_namespace("Some-Namespace", "cpan") == "SOME-NAMESPACE"

for ptype in ("pan", "cpa", "c", "a", "cp", "an"):
assert normalize_namespace("Some-Namespace", ptype) == "Some-Namespace"

assert PackageURL(type="pan", namespace="Some-Namespace", name="x").to_string() == (
"pkg:pan/Some-Namespace/x"
)


def test_mlflow_name_handling_is_not_applied_to_substring_types() -> None:
databricks = {"repository_url": "https://community.cloud.databricks.com"}

assert normalize_name("MyModel", databricks, "mlflow") == "mymodel"

for ptype in ("ml", "flow", "low", "m", "w"):
assert normalize_name("MyModel", databricks, ptype) == "MyModel"