Skip to content

Commit b728a75

Browse files
committed
Add normalization for pub packages
Signed-off-by: Tushar Goel <[email protected]>
1 parent 8317634 commit b728a75

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/packageurl/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,15 @@ def normalize_name(
188188
"apk",
189189
"bitnami",
190190
"hex",
191+
"pub",
191192
):
192193
name_str = name_str.lower()
193194
if ptype == "pypi":
194195
name_str = name_str.replace("_", "-").lower()
195196
if ptype == "hackage":
196197
name_str = name_str.replace("_", "-")
198+
if ptype == "pub":
199+
name_str = re.sub(r"[^a-z0-9]", "_", name_str.lower())
197200
return name_str or None
198201

199202

src/packageurl/validate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,13 +552,13 @@ class PubTypeValidator(TypeValidator):
552552
def validate_type(cls, purl, strict=False):
553553
if not all(c.isalnum() or c == "_" for c in purl.name):
554554
yield ValidationMessage(
555-
severity=ValidationSeverity.ERROR,
555+
severity=ValidationSeverity.WARNING,
556556
message=f"Name contains invalid characters but should only contain letters, digits, or underscores for purl type: {cls.type!r}",
557557
)
558558

559559
if " " in purl.name:
560560
yield ValidationMessage(
561-
severity=ValidationSeverity.ERROR,
561+
severity=ValidationSeverity.WARNING,
562562
message=f"Name contains spaces but should use underscores instead for purl type: {cls.type!r}",
563563
)
564564
messages = super().validate_type(purl, strict)

0 commit comments

Comments
 (0)