Skip to content

Commit

Permalink
and empty license expression is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
ewdurbin committed Sep 13, 2024
1 parent cd7105f commit e469b7e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/packaging/licenses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ class InvalidLicenseExpression(ValueError):


def normalize_license_expression(raw_license_expression: str) -> str | None:
if not raw_license_expression:
return None
if raw_license_expression == "":
message = (
f"Invalid license expression: {raw_license_expression}"
)
raise InvalidLicenseExpression(message)

license_refs = {
ref.lower(): "LicenseRef-" + ref[11:]
Expand Down
3 changes: 1 addition & 2 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,6 @@ def test_optional_defaults_to_none(self, field_name):
("LicenseRef-Proprietary", "LicenseRef-Proprietary"),
("LicenseRef-Beerware-4.2", "LicenseRef-Beerware-4.2"),
("licenseref-beerware-4.2", "LicenseRef-beerware-4.2"),
("", None),
(None, None),
],
)
def test_valid_license_expression(self, license_expression, expected):
Expand All @@ -684,6 +682,7 @@ def test_valid_license_expression(self, license_expression, expected):
@pytest.mark.parametrize(
"license_expression",
[
"",
"Use-it-after-midnight",
"LicenseRef-License with spaces",
"LicenseRef-License_with_underscores",
Expand Down

0 comments on commit e469b7e

Please sign in to comment.