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 @@ -8,6 +8,9 @@ Changelog

- Drop support for Python 3.8

- Normalize OCI and Hugging Face versions consistently when the package type
contains uppercase characters or is supplied as bytes.

- Fix type hint for ``BasePurlType.allowed_qualifiers``
https://github.com/package-url/packageurl-python/pull/213

Expand Down
2 changes: 1 addition & 1 deletion src/packageurl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def normalize(
type_norm = normalize_type(type, encode)
namespace_norm = normalize_namespace(namespace, type_norm, encode)
name_norm = normalize_name(name, qualifiers, type_norm, encode)
version_norm = normalize_version(version, type, encode)
version_norm = normalize_version(version, type_norm, encode)
qualifiers_norm = normalize_qualifiers(qualifiers, encode)
subpath_norm = normalize_subpath(subpath, encode)
return type_norm, namespace_norm, name_norm, version_norm, qualifiers_norm, subpath_norm
Expand Down
25 changes: 25 additions & 0 deletions tests/test_packageurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,36 @@
import re
import unittest

import pytest

from packageurl import PackageURL
from packageurl import normalize
from packageurl import normalize_qualifiers


@pytest.mark.parametrize("ptype", ["OCI", "Oci", b"oci", "HuggingFace", b"huggingface"])
def test_version_normalization_uses_normalized_type(ptype):
purl = PackageURL(type=ptype, name="example", version="ABCDEF")

assert purl.version == "abcdef"
assert purl == PackageURL.from_string(purl.to_string())


@pytest.mark.parametrize("encode", [True, False, None])
@pytest.mark.parametrize("ptype", ["OCI", b"oci", "HuggingFace", b"huggingface"])
def test_normalize_version_with_normalized_type(ptype, encode):
normalized = normalize(ptype, None, "example", "ABCDEF", None, None, encode=encode)

assert normalized[3] == "abcdef"


def test_case_sensitive_version_is_preserved_with_normalized_type():
purl = PackageURL(type="Maven", name="example", version="1.0-RC1")

assert purl.version == "1.0-RC1"
assert purl == PackageURL.from_string(purl.to_string())


def create_test_function(
description,
purl,
Expand Down