From 8db56e6800c951c9d5f90d275632312bb5d07329 Mon Sep 17 00:00:00 2001 From: Dennys Kaluzny Pereira <64793570+protonnegativo@users.noreply.github.com> Date: Fri, 13 Nov 2026 21:50:16 +0000 Subject: [PATCH] fix(python): keep single-character names in requirements.txt (#5469) namePattern required at least two characters, so a pinned line like "q==2.7" (the format pip freeze writes) didn't match and the package was dropped from the SBOM. PEP 508 allows one-character names (q, a, j and others exist on PyPI). Signed-off-by: protonnegativo Co-authored-by: protonnegativo --- syft/pkg/cataloger/python/parse_requirements.go | 2 +- .../cataloger/python/parse_requirements_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/syft/pkg/cataloger/python/parse_requirements.go b/syft/pkg/cataloger/python/parse_requirements.go index ed3536d0f..cae087097 100644 --- a/syft/pkg/cataloger/python/parse_requirements.go +++ b/syft/pkg/cataloger/python/parse_requirements.go @@ -26,7 +26,7 @@ const ( // --hash=sha256:e9535b8c84dc9571a48999094fda7f33e63c3f1b74f3e5f3ac0105a58405bb65 # some comment // namePattern matches: requests[security] - namePattern = `(?P\w[\w\[\],\s-_\.]+)` + namePattern = `(?P\w[\w\[\],\s-_\.]*)` // versionConstraintPattern matches: == 2.8.* // the version token accepts every character PEP 440 versions can contain: digits and letters, diff --git a/syft/pkg/cataloger/python/parse_requirements_test.go b/syft/pkg/cataloger/python/parse_requirements_test.go index 1175f7e4d..01fe0dd6d 100644 --- a/syft/pkg/cataloger/python/parse_requirements_test.go +++ b/syft/pkg/cataloger/python/parse_requirements_test.go @@ -318,6 +318,21 @@ func Test_newRequirement(t *testing.T) { VersionConstraint: "==2.8", }, }, + { + name: "single character name", + raw: "q==2.7", + want: &unprocessedRequirement{ + Name: "q", + VersionConstraint: "==2.7", + }, + }, + { + name: "single character name without version", + raw: "q", + want: &unprocessedRequirement{ + Name: "q", + }, + }, { name: "arbitrary equality", raw: "urllib3===1.26.20",