[BUG] get_dependencies in nuget.py crashes with KeyError: '@targetFramework' on dependency groups without targetFramework
I maintainer di solito rispondono entro 2 giorni
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Start with get_dependencies() in src/packagedcode/nuget.py and inspect the existing NuGet package tests for .nuspec dependency groups and license parsing. The issue also reports that packages.lock.json project references of type Project are rejected; check the related lockfile handling and tests. Reproduce the fallback group crash, then confirm all three reported cases are covered and scans complete without errors.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
In NuGet .nuspec manifests, dependency <group> elements can specify target frameworks. According to Microsoft's NuGet nuspec reference documentation:
"A
<dependencies>element can contain one<group>tag without atargetFrameworkattribute to specify a fallback group that is applied when no specific targetFramework matches the project."
Currently, scancode-toolkit's get_dependencies() in src/packagedcode/nuget.py accesses group['@targetFramework'] directly:
for group in groups:
extra_data = dict(framework=group['@targetFramework'])
deps = group.get('dependency') or []
yield from _get_dep_packs(deps, extra_data)
When scanning any .nuspec that includes a fallback <group> without targetFramework, this raises an unhandled KeyError: '@targetFramework' and aborts the scan.
Additionally:
- When
<license type="expression">...</license>is used in.nuspec,xmltodictparses the element as a dictionary ({'@type': 'expression', '#text': '...'}). Becausenuspec.get('license')was passed directly,extracted_license_statementreceived the dictionary, resulting in a stringified mapping rather than extracting the license expression string. - In
packages.lock.json, project references with"type": "Project"were not recognized, raisingException: Unknown package type: Project.
How To Reproduce
- Create a
test.nuspecwith a fallback group:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>SamplePackage</id>
<version>1.0.0</version>
<dependencies>
<group>
<dependency id="FallbackDep" version="1.0.0" />
</group>
<group targetFramework="net6.0">
<dependency id="Net6Dep" version="2.0.0" />
</group>
</dependencies>
</metadata>
</package>
- Scan the file:
./scancode --package --json - test.nuspec
- Observe traceback:
KeyError: '@targetFramework'
Expected Behavior
- Dependencies in a fallback
<group>withouttargetFrameworkshould be extracted without crashing. extra_data['framework']should be set whentargetFrameworkis present, or omitted when absent.- The
<license>element text should be cleanly extracted even when attributes liketype="expression"are present.
System configuration
- OS: macOS / Linux / Windows
- 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
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di aboutcode-org/scancode-toolkit
-
yarn.lock v1 with a scoped alias of an unscoped package yields no packages and no errorForse già presa @Shubham-dev-stack l’ha presa 6 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
aboutcode-org/scancode-toolkit#5466 ·
I maintainer di solito rispondono entro 2 giorni
-
package-lock.json dependencies report file_references as a list inside a listForse già presa @Anbarasu2410 l’ha presa 9 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
aboutcode-org/scancode-toolkit#5449 · 4 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
scancode aborts when encountering a broken RPM archiveForse già presa @Ashutosh-Panda2004 l’ha presa 14 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
aboutcode-org/scancode-toolkit#5407 · 3 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
Four silent bugs: IsRequiredPhrase.license_expression returns None, find_in_path ignores later PATH changes, duplicate dict keys override license mappingsForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabug
Difficoltà 2/5 Mezza giornata Idoneità per principianti 65/100
aboutcode-org/scancode-toolkit#5405 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
parse_maintainer_name_email returns empty name and wrong email when string has "@" but no angle bracketsForse già presa @RohitSutar1823 l’ha presa 14 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
aboutcode-org/scancode-toolkit#5402 ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di aboutcode-org/scancode-toolkit
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
GoogleCloudPlatform/professional-services-data-validator#1899 ·
I maintainer di solito rispondono entro 4 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
mohanraj00/entelos#200 ·
I maintainer di solito rispondono entro 1 giorno
-
Dead url in mise.tomlAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
-
sweep
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
bketelsen/truenas-mcp#77 ·
I maintainer di solito rispondono entro 1 giorno
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
sandbox-quantum/switch#2163 ·
I maintainer di solito rispondono entro 1 giorno