diff --git a/src/python_inspector/dependencies.py b/src/python_inspector/dependencies.py index 0c491304..31328fc3 100644 --- a/src/python_inspector/dependencies.py +++ b/src/python_inspector/dependencies.py @@ -65,7 +65,7 @@ def get_dependency(specifier) -> DependentPackage: >>> dep = get_dependency("foo==1.2.3") >>> assert dep.purl == "pkg:pypi/foo@1.2.3" """ - specifier = specifier and "".join(specifier.lower().split()) + specifier = specifier and specifier.strip() assert specifier, f"specifier is required but empty:{specifier!r}" requirement = Requirement(requirement_string=specifier) diff --git a/tests/test_requirement_text.py b/tests/test_requirement_text.py new file mode 100644 index 00000000..4dc9607a --- /dev/null +++ b/tests/test_requirement_text.py @@ -0,0 +1,17 @@ +# Copyright (c) nexB Inc. and others. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# See https://github.com/aboutcode-org/python-inspector for support or download. + +import pytest + +from python_inspector.dependencies import get_dependency + + +@pytest.mark.parametrize( + "text", + ['Demo==1.2; sys_platform == "Windows Server"', "Demo @ https://example.org/Release/Demo.whl"], +) +def test_dependency_preserves_requirement_text(text): + dependency = get_dependency(" " + text + " ") + assert dependency.extracted_requirement == text + assert dependency.purl.startswith("pkg:pypi/demo")