Clarify .exe suffix handling in class normalization
This commit is contained in:
@@ -14,8 +14,9 @@ func ClassFromImagePath(p string) string {
|
||||
if i := strings.LastIndexAny(p, `\/`); i >= 0 {
|
||||
p = p[i+1:]
|
||||
}
|
||||
if len(p) >= 4 && strings.EqualFold(p[len(p)-4:], ".exe") {
|
||||
p = p[:len(p)-4]
|
||||
const exeSuffix = ".exe"
|
||||
if len(p) >= len(exeSuffix) && strings.EqualFold(p[len(p)-len(exeSuffix):], exeSuffix) {
|
||||
p = p[:len(p)-len(exeSuffix)]
|
||||
}
|
||||
return strings.ToLower(p)
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ func TestClassFromImagePath(t *testing.T) {
|
||||
{`C:/forward/slash/Code.exe`, "code"},
|
||||
{`firefox`, "firefox"},
|
||||
{``, ""},
|
||||
{`.exe`, ""}, // degenerate: only the extension
|
||||
}
|
||||
for _, c := range cases {
|
||||
if got := ClassFromImagePath(c.in); got != c.want {
|
||||
|
||||
Reference in New Issue
Block a user