Cargo.toml: Dependencies renamed using the package key yield incorrect package name and purl

Offen
#5,476 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@patelshivani2283-lab arbeitet bereits daran.

Seit 13.11.2026.

  • #5477 von @patelshivani2283-lab — offen

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
25/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
python, rust
Bereich
backend

Rechercherichtung

Start with CargoTomlHandler and the dependency_mapper it uses, where the dictionary key is taken as the package name. Read the package key handling first, since the issue says it is left unhandled in extra_data. Pull request #5477 is already open against this issue, so check its state before starting. Done means purl is pkg:cargo/regex for the example and the alias is kept in extra_data['alias'].

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Description

In Rust Cargo.toml, dependencies can be renamed using the package key as documented in the Cargo Reference on Renaming Dependencies:

[dependencies]
my_regex = { version = "1.5.0", package = "regex" }

In this case, my_regex is only the local alias used in code, while the actual crate published on crates.io is regex.

Currently, scancode-toolkit's CargoTomlHandler / dependency_mapper takes the dictionary key (my_regex) as the package name:

  • Generated purl: pkg:cargo/my_regex (incorrect)
  • Expected purl: pkg:cargo/regex (correct)

Because pkg:cargo/my_regex does not point to the actual dependency crate, downstream package and vulnerability lookups on crates.io fail or look up the wrong package. The package key also remains unhandled in extra_data.

How To Reproduce
  1. Create a Cargo.toml with a renamed dependency:
    [package]
    name = "test-pkg"
    version = "0.1.0"
    
    [dependencies]
    my_regex = { version = "1.5.0", package = "regex" }
    
  2. Scan the file with ScanCode:
    ./scancode --package --json - Cargo.toml
    
  3. Observe dependencies:
    • It outputs purl: "pkg:cargo/my_regex" instead of pkg:cargo/regex.
Expected Behavior
  • purl should reflect the target package name (pkg:cargo/regex).
  • The local alias (my_regex) should be preserved in extra_data['alias'].
System configuration
  • OS: macOS / Linux
  • ScanCode version: 33.0.0rc1 / develop branch
  • Python version: 3.10+
Vorherrschende Sprache
Python
Sterne
2.7k
Forks
871
Ø Merge
1 T. 10 Std.
Gemergte PRs (30 T.)
3

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus aboutcode-org/scancode-toolkit

Alle Issues in aboutcode-org/scancode-toolkit

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.