Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/core/purl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function parsePURL(purlStr: string): ParsedPURL {

// Ecosystem-specific normalization per PURL spec
if (type === "pypi") {
name = name.toLowerCase().replace(/_/g, "-");
name = name.toLowerCase().replace(/[-_.]+/g, "-");
}

if (type === "alpm") {
Expand Down
4 changes: 2 additions & 2 deletions src/registries/pypi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class PyPIRegistry implements Registry {

/** Normalize package name per PEP 503. */
private normalizeName(name: string): string {
return name.toLowerCase().replace(/_/g, "-");
return name.toLowerCase().replace(/[-_.]+/g, "-");
}

/** Extract repository URL from project_urls. */
Expand Down Expand Up @@ -289,7 +289,7 @@ class PyPIRegistry implements Registry {
}

return {
name: depName,
name: this.normalizeName(depName),
requirements: versionSpec,
scope,
optional,
Expand Down
8 changes: 8 additions & 0 deletions test/unit/purl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ describe("purl", () => {
expect(result.version).toBe("3.14.0");
});

it("normalizes PyPI dots and separator runs per PEP 503", () => {
expect(parsePURL("pkg:pypi/my.package").name).toBe("my-package");
expect(parsePURL("pkg:pypi/my..package").name).toBe("my-package");
expect(parsePURL("pkg:pypi/my--package").name).toBe("my-package");
expect(parsePURL("pkg:pypi/my_-_package").name).toBe("my-package");
expect(parsePURL("pkg:pypi/Babel.js").name).toBe("babel-js");
});

it("throws on missing pkg: prefix", () => {
expect(() => parsePURL("npm/lodash")).toThrow(InvalidPURLError);
expect(() => parsePURL("npm/lodash")).toThrow('must start with "pkg:"');
Expand Down