Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ package_dir = =src
include_package_data = true
zip_safe = false
install_requires =
univers>=30.12.1

[options.packages.find]
where = src
Expand Down
5 changes: 5 additions & 0 deletions src/packageurl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@

AnyStr = Union[str, bytes]

from univers.version_range import VersionRange

# Python 3
basestring = (bytes, str)

Expand Down Expand Up @@ -221,6 +223,9 @@ def normalize_qualifiers(
if key[0] in string.digits:
raise ValueError(f"A qualifier key cannot start with a number: {key!r}")

if vers := qualifiers_map.get("vers"):
VersionRange.from_string(vers, validate=True)

qualifiers_map = dict(sorted(qualifiers_map.items()))

if not encode:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_packageurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import re
import unittest

import pytest

from packageurl import PackageURL
from packageurl import normalize
from packageurl import normalize_qualifiers
Expand Down Expand Up @@ -374,3 +376,13 @@ def test_encoding_stuff_with_colons_correctly() -> None:
p.to_string()
== "pkg:nuget/an:odd:space/libiconv:%20character%20set%20conversion%20library@1.9?package-id=e11a609df352e292"
)


def test_vers_validation_ok():
url = PackageURL.from_string("pkg:pypi/requests?vers=vers:pypi/>=2.0")
assert url.qualifiers["vers"] == "vers:pypi/>=2.0"


def test_vers_validation_fails():
with pytest.raises(ValueError, match="must start with the 'vers:' URI scheme."):
PackageURL.from_string("pkg:pypi/requests?vers=>=2.0")
Loading