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

Aperta
#5,476 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@patelshivani2283-lab ci sta già lavorando.

Dal 13/11/2026.

  • #5477 di @patelshivani2283-lab — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, rust
Ambito
backend

Direzione di ricerca

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'].

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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+
Lingua principale
Python
Stelle
2.7k
Fork
871
Merge medio
1g 10h
PR unite (30g)
3

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di aboutcode-org/scancode-toolkit

Tutte le issue di aboutcode-org/scancode-toolkit

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.