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

Open
#5,476 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

@patelshivani2283-lab is already working on this.

Since Nov 13, 2026.

  • #5477 by @patelshivani2283-lab — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
25/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python, rust
Domain
backend

Research direction

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

Written by the indexing model from the issue text.

Description

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+
Dominant language
Python
Stars
2.7k
Forks
871
Avg merge
1d 10h
Merged PRs (30d)
3

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from aboutcode-org/scancode-toolkit

All issues in aboutcode-org/scancode-toolkit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.