From 8da1336917c763da16bc6466928c796f269548e8 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Wed, 14 Jan 2026 20:44:06 +0700 Subject: all: handle binary file in post-scan File that match with match-file-pattern but without prefix and suffix will be marked as binary. --- file.go | 11 ++++++++++- report.go | 6 ++++++ spdxconv_test.go | 2 ++ testdata/scan/test.json | 1 + 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 testdata/scan/test.json diff --git a/file.go b/file.go index 42bc245..0ac312a 100644 --- a/file.go +++ b/file.go @@ -120,7 +120,16 @@ func (f *file) initLines(content []byte, maxLine int) (err error) { func (f *file) scan(conv *SPDXConv) { f.detectComment(&conv.cfg) - if f.isBinary || f.isUnknown { + if f.isBinary { + f.licenseID = valDefault + f.copyrightText = valDefault + f.getYearFromSCM(conv) + if f.copyrightYear == `` { + f.copyrightYear = conv.cfg.CopyrightYear + } + return + } + if f.isUnknown { return } f.scanLicenseID(conv) diff --git a/report.go b/report.go index 5296bef..b33149a 100644 --- a/report.go +++ b/report.go @@ -124,6 +124,12 @@ func (rep *report) scan(conv *SPDXConv, listFile []string) (err error) { continue } f.scan(conv) + if f.isBinary { + // json file should be detected as binary, since its + // does not have comment syntax. + rep.listBinary = append(rep.listBinary, f) + continue + } if f.isUnknown { rep.listUnknown = append(rep.listUnknown, f) continue diff --git a/spdxconv_test.go b/spdxconv_test.go index d73c69f..5186504 100644 --- a/spdxconv_test.go +++ b/spdxconv_test.go @@ -143,6 +143,7 @@ test.sql,match,1,2022,match,0,--, // //spdxconv:binary // +test.json,default,0,2025,default,0,, // //spdxconv:unknown // @@ -341,6 +342,7 @@ func TestSPDXConv_scanDir(t *testing.T) { `po/included.go`, `test.go`, `test.html`, + `test.json`, `test.sh`, `test.sql`, `with_spdx.go`, diff --git a/testdata/scan/test.json b/testdata/scan/test.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/testdata/scan/test.json @@ -0,0 +1 @@ +{} -- cgit v1.3