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'
This commit is contained in:
Clayton Craft
2021-09-01 11:03:38 -07:00
parent ad2ffc4191
commit d0fc2d258f
2 changed files with 2 additions and 1 deletions

View File

@@ -614,7 +614,7 @@ func stripExts(file string) string {
if filepath.Ext(file) == "" { if filepath.Ext(file) == "" {
break break
} }
file = strings.Trim(file, filepath.Ext(file)) file = strings.TrimSuffix(file, filepath.Ext(file))
} }
return file return file
} }

View File

@@ -15,6 +15,7 @@ func TestStripExts(t *testing.T) {
{"file.tar.gz.xz.zip", "file"}, {"file.tar.gz.xz.zip", "file"},
{"another_file", "another_file"}, {"another_file", "another_file"},
{"a.b.c.d.e.f.g.h.i", "a"}, {"a.b.c.d.e.f.g.h.i", "a"},
{"virtio_blk.ko", "virtio_blk"},
} }
for _, table := range tables { for _, table := range tables {
out := stripExts(table.in) out := stripExts(table.in)