[BUG] get_dependencies in nuget.py crashes with KeyError: '@targetFramework' on dependency groups without targetFramework
维护者通常 1 天内回复
评估
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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+
- 主要语言
- Python
- 星标
- 2.7k
- 派生
- 871
- 平均合并
- 1 天 10 小时
- 30 天内合并 PR
- 3
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
aboutcode-org/scancode-toolkit 的其他 Issue
-
yarn.lock v1 with a scoped alias of an unscoped package yields no packages and no error可能已有人在做 @Shubham-dev-stack 于 6 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 74/100
aboutcode-org/scancode-toolkit#5466 ·
维护者通常 1 天内回复
-
package-lock.json dependencies report file_references as a list inside a list可能已有人在做 @Anbarasu2410 于 9 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 82/100
aboutcode-org/scancode-toolkit#5449 · 4 条评论 ·
维护者通常 1 天内回复
-
scancode aborts when encountering a broken RPM archive可能已有人在做 @Ashutosh-Panda2004 于 14 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 62/100
aboutcode-org/scancode-toolkit#5407 · 3 条评论 ·
维护者通常 1 天内回复
-
Four silent bugs: IsRequiredPhrase.license_expression returns None, find_in_path ignores later PATH changes, duplicate dict keys override license mappings可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭bug
难度 2/5 半天 新手友好度 65/100
aboutcode-org/scancode-toolkit#5405 · 1 条评论 ·
维护者通常 1 天内回复
-
parse_maintainer_name_email returns empty name and wrong email when string has "@" but no angle brackets可能已有人在做 @RohitSutar1823 于 15 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 84/100
aboutcode-org/scancode-toolkit#5402 ·
维护者通常 1 天内回复
查看 aboutcode-org/scancode-toolkit 的全部 Issue
相似的 Issue
-
author-page correction move-papers
难度 1/5 1 小时以内 新手友好度 78/100
acl-org/acl-anthology#10978 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
GoogleCloudPlatform/professional-services-data-validator#1899 ·
维护者通常 4 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
HKUDS/CLI-Anything#652 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
Project-N-E-K-O/N.E.K.O#3813 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
Dao-AILab/flash-attention#3191 ·
维护者通常 4 天内回复