From 155a7bc17fe8c2f846278a97465401520d85926e Mon Sep 17 00:00:00 2001 From: Clayton Craft Date: Wed, 1 Sep 2021 11:03:38 -0700 Subject: [PATCH] stripExts: don't use a cutset when removing extension I misread what strings.Trim does, the 2nd param is a _cut set_, so this was removing any occurance any characters in the 2nd param. Since the file extension is always a suffix, this uses TrimSuffix. Fixes a bug where 'virtio_blk.ko' was being trimmed to 'virtio_bl' --- main.go | 2 +- main_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index e741541..699de0a 100644 --- a/main.go +++ b/main.go @@ -614,7 +614,7 @@ func stripExts(file string) string { if filepath.Ext(file) == "" { break } - file = strings.Trim(file, filepath.Ext(file)) + file = strings.TrimSuffix(file, filepath.Ext(file)) } return file } diff --git a/main_test.go b/main_test.go index aa3a6ec..27775fc 100644 --- a/main_test.go +++ b/main_test.go @@ -15,6 +15,7 @@ func TestStripExts(t *testing.T) { {"file.tar.gz.xz.zip", "file"}, {"another_file", "another_file"}, {"a.b.c.d.e.f.g.h.i", "a"}, + {"virtio_blk.ko", "virtio_blk"}, } for _, table := range tables { out := stripExts(table.in)