Clarify .exe suffix handling in class normalization

This commit is contained in:
2026-06-02 12:21:12 -04:00
parent 4ea8aed04b
commit f79c149039
2 changed files with 4 additions and 2 deletions
+3 -2
View File
@@ -14,8 +14,9 @@ func ClassFromImagePath(p string) string {
if i := strings.LastIndexAny(p, `\/`); i >= 0 { if i := strings.LastIndexAny(p, `\/`); i >= 0 {
p = p[i+1:] p = p[i+1:]
} }
if len(p) >= 4 && strings.EqualFold(p[len(p)-4:], ".exe") { const exeSuffix = ".exe"
p = p[:len(p)-4] if len(p) >= len(exeSuffix) && strings.EqualFold(p[len(p)-len(exeSuffix):], exeSuffix) {
p = p[:len(p)-len(exeSuffix)]
} }
return strings.ToLower(p) return strings.ToLower(p)
} }
+1
View File
@@ -12,6 +12,7 @@ func TestClassFromImagePath(t *testing.T) {
{`C:/forward/slash/Code.exe`, "code"}, {`C:/forward/slash/Code.exe`, "code"},
{`firefox`, "firefox"}, {`firefox`, "firefox"},
{``, ""}, {``, ""},
{`.exe`, ""}, // degenerate: only the extension
} }
for _, c := range cases { for _, c := range cases {
if got := ClassFromImagePath(c.in); got != c.want { if got := ClassFromImagePath(c.in); got != c.want {