[BUG] build_dep in pubspec.py crashes with AttributeError on path, git, or unversioned dependencies
メンテナーはふだん 2 日以内に返信
@Adnan9-63 がすでに取り組んでいます。
2026年11月17日 から。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 35/100
調査の方向性
Read src/packagedcode/pubspec.py, especially build_dep and collect_deps, then reproduce with the pubspec.yaml shown in the issue. Check whether path, git, and unversioned dependencies parse without crashing and retain their dependency data. Done means the scan returns dependencies instead of an empty package list; linked pull request #5492 is already open.
索引モデルが issue の本文から書いたものです。
説明
Problem Description
In src/packagedcode/pubspec.py, the build_dep function assumes version is always a string containing a version number.
When a pubspec.yaml contains:
- Path dependencies (e.g.
path: ../local_pkg) - Git dependencies (e.g.
git: https://github.com/...) - Unversioned dependencies (e.g.
collection:where YAML parses the value asNone)
build_dep crashes with an AttributeError because it calls .replace('.', '') directly on version without verifying that it is a string.
During a scan (scancode --package), this unhandled exception causes ScanCode to fail silently on pubspec.yaml, returning 0 packages and missing all dependencies.
Steps to Reproduce
- Create a
pubspec.yamlcontaining a path dependency and an unversioned dependency:
name: my_flutter_app
version: 1.0.0
dependencies:
flutter:
sdk: flutter
my_local_package:
path: ../my_local_package
collection:
- Run a package scan:
scancode --package --json-pp scan.json pubspec.yaml
-
scan.jsonreportspackages: [](dependencies are completely lost). -
Directly calling
DartPubspecYamlHandler.parsereveals the traceback:
Traceback (most recent call last):
File "src/packagedcode/pubspec.py", line 288, in build_package
package_dependencies.extend(dependencies)
File "src/packagedcode/pubspec.py", line 193, in collect_deps
dep = build_dep(...)
File "src/packagedcode/pubspec.py", line 216, in build_dep
if version.replace('.', '').isdigit():
AttributeError: 'dict' object has no attribute 'replace'
(Or AttributeError: 'NoneType' object has no attribute 'replace' if version is None).
Root Cause
In src/packagedcode/pubspec.py, line 216:
def build_dep(name, version, scope, is_runtime=True, is_optional=False):
if isinstance(version, dict) and 'sdk' in version:
version = ', '.join(': '.join([k, str(v)]) for k, v in version.items())
if version.replace('.', '').isdigit():
purl = PackageURL(
type='pubspec',
name=name,
version=version,
)
is_pinned = True
- If
versionisNone,version.replace(...)raisesAttributeError: 'NoneType' object has no attribute 'replace'. - If
versionis adict(such as{'path': '...'}or{'git': '...'}),version.replace(...)raisesAttributeError: 'dict' object has no attribute 'replace'.
Expected Behavior
- Path and git dependencies should not crash the parser; their mapping should be safely preserved in
extra_data. - Unversioned dependencies should result in a valid
DependentPackagewithextracted_requirement=Noneandis_pinned=False.
Proposed Solution
Safely check types and extract version/extra_data in build_dep:
def build_dep(name, version, scope, is_runtime=True, is_optional=False):
extra_data = {}
extracted_requirement = None
is_pinned = False
if isinstance(version, dict):
if 'sdk' in version:
extracted_requirement = ', '.join(': '.join([k, str(v)]) for k, v in version.items())
else:
extra_data = version
if 'version' in version and isinstance(version['version'], str):
extracted_requirement = version['version']
elif isinstance(version, str):
extracted_requirement = version
if extracted_requirement and isinstance(extracted_requirement, str) and extracted_requirement.replace('.', '').isdigit():
purl = PackageURL(
type='pubspec',
name=name,
version=extracted_requirement,
)
is_pinned = True
else:
purl = PackageURL(
type='pubspec',
name=name,
)
dep = models.DependentPackage(
purl=purl.to_string(),
extracted_requirement=extracted_requirement,
scope=scope,
is_runtime=is_runtime,
is_optional=is_optional,
is_pinned=is_pinned,
extra_data=extra_data,
)
return dep
Environment
- ScanCode version: 33.0.0rc1 / develop branch
- OS: All
- 主要言語
- Python
- スター
- 2.7k
- フォーク
- 871
- 平均マージ
- 1日 10時間
- マージ済み PR(30日)
- 3
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 ·
メンテナーはふだん 2 日以内に返信
-
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 件 ·
メンテナーはふだん 2 日以内に返信
-
scancode aborts when encountering a broken RPM archive対応中かも @Ashutosh-Panda2004 が 14 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
aboutcode-org/scancode-toolkit#5407 · コメント 3 件 ·
メンテナーはふだん 2 日以内に返信
-
Four silent bugs: IsRequiredPhrase.license_expression returns None, find_in_path ignores later PATH changes, duplicate dict keys override license mappings対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンbug
難易度 2/5 半日 初心者へのやさしさ 65/100
aboutcode-org/scancode-toolkit#5405 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
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 ·
メンテナーはふだん 2 日以内に返信
aboutcode-org/scancode-toolkit の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
GoogleCloudPlatform/professional-services-data-validator#1899 ·
メンテナーはふだん 4 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
mohanraj00/entelos#200 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
-
sweep
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
bketelsen/truenas-mcp#77 ·
メンテナーはふだん 1 日以内に返信
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskオープン
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
sandbox-quantum/switch#2163 ·
メンテナーはふだん 1 日以内に返信