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 {
|
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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user