Skip to content

Fix urls command using version ranges and wrong name from db lookup - #240

Merged
andrew merged 1 commit into
mainfrom
urls-lookup-fix
Jun 21, 2026
Merged

andrew merged 1 commit into
mainfrom
urls-lookup-fix

Conversation

@andrew

@andrew andrew commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Fixes #239.

lookupPackage had two problems when resolving a plain name from the database:

  • It returned the original query string as the package name even when the match came from a substring search, so git pkgs urls lod -e npm built URLs for lod using lodash's data.
  • It returned the manifest requirement (e.g. ^4.17.21) as the version, producing invalid download URLs like https://registry.npmjs.org/lodash/-/lodash-^4.17.21.tgz and purls like pkg:npm/lodash@^4.17.21.

This change keeps the full SearchResult through the dedup so the matched name is returned, prefers lockfile rows over manifest rows for the same ecosystem, and only passes the requirement through as a version when it is known to be exact (lockfile entries, or go.mod / Maven manifests). Otherwise the version is left empty and registries.BuildURLs emits a versionless purl and skips the download URL.

The lockfile/golang/maven check is pulled out of isResolvedDependency into hasResolvedRequirement so both call sites share it.

@abhinavgautam01

Copy link
Copy Markdown
Contributor

LGTM,
i reviewed the diff against #239 and the fix covers both cases: substring lookup now returns the matched package name and manifest-only version ranges are no longer treated as exact versions for download URLs. The added tests cover manifest-only npm, lockfile npm, substring lookup and Go exact-version behavior.

@andrew
andrew merged commit ea8f727 into main Jun 21, 2026
7 checks passed
@andrew
andrew deleted the urls-lookup-fix branch June 21, 2026 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

git pkgs urls can generate invalid URLs from database lookups

2 participants