[BUG] build_dep in pubspec.py crashes with AttributeError on path, git, or unversioned dependencies
Maintainer thường phản hồi trong vòng 2 ngày
@Adnan9-63 đang làm issue này rồi.
Từ ngày 17/11/2026.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Python
- Star
- 2.7k
- Fork
- 871
- Merge trung bình
- 1 ngày 10 giờ
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của aboutcode-org/scancode-toolkit
-
yarn.lock v1 with a scoped alias of an unscoped package yields no packages and no errorCó thể đã có người làm @Shubham-dev-stack đã nhận 6 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
aboutcode-org/scancode-toolkit#5466 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
package-lock.json dependencies report file_references as a list inside a listCó thể đã có người làm @Anbarasu2410 đã nhận 9 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
aboutcode-org/scancode-toolkit#5449 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
scancode aborts when encountering a broken RPM archiveCó thể đã có người làm @Ashutosh-Panda2004 đã nhận 14 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
aboutcode-org/scancode-toolkit#5407 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Four silent bugs: IsRequiredPhrase.license_expression returns None, find_in_path ignores later PATH changes, duplicate dict keys override license mappingsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 65/100
aboutcode-org/scancode-toolkit#5405 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
parse_maintainer_name_email returns empty name and wrong email when string has "@" but no angle bracketsCó thể đã có người làm @RohitSutar1823 đã nhận 15 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
aboutcode-org/scancode-toolkit#5402 ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của aboutcode-org/scancode-toolkit
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
GoogleCloudPlatform/professional-services-data-validator#1899 ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
mohanraj00/entelos#200 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Dead url in mise.tomlĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
-
sweep
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
bketelsen/truenas-mcp#77 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
sandbox-quantum/switch#2163 ·
Maintainer thường phản hồi trong vòng 1 ngày