mirror of
https://github.com/safing/portbase
synced 2025-09-01 18:19:57 +00:00
Fix executable suffix detection
This commit is contained in:
parent
8a1917c4e0
commit
0aeb007138
2 changed files with 20 additions and 3 deletions
|
@ -25,9 +25,21 @@ func GenerateBinaryNameFromPath(path string) string {
|
|||
segments := segmentsSplitter.FindAllString(fileName, -1)
|
||||
|
||||
// Remove last segment if it's an extension.
|
||||
if len(segments) >= 2 &&
|
||||
strings.HasPrefix(segments[len(segments)-1], ".") {
|
||||
segments = segments[:len(segments)-1]
|
||||
if len(segments) >= 2 {
|
||||
switch strings.ToLower(segments[len(segments)-1]) {
|
||||
case
|
||||
".exe", // Windows Executable
|
||||
".msi", // Windows Installer
|
||||
".bat", // Windows Batch File
|
||||
".cmd", // Windows Command Script
|
||||
".ps1", // Windows Powershell Cmdlet
|
||||
".run", // Linux Executable
|
||||
".appimage", // Linux AppImage
|
||||
".app", // MacOS Executable
|
||||
".action", // MacOS Automator Action
|
||||
".out": // Generic Compiled Executable
|
||||
segments = segments[:len(segments)-1]
|
||||
}
|
||||
}
|
||||
|
||||
// Debugging snippet:
|
||||
|
|
|
@ -7,6 +7,8 @@ import (
|
|||
)
|
||||
|
||||
func TestGenerateBinaryNameFromPath(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
assert.Equal(t, "Nslookup", GenerateBinaryNameFromPath("nslookup.exe"))
|
||||
assert.Equal(t, "System Settings", GenerateBinaryNameFromPath("SystemSettings.exe"))
|
||||
assert.Equal(t, "One Drive Setup", GenerateBinaryNameFromPath("OneDriveSetup.exe"))
|
||||
|
@ -18,9 +20,12 @@ func TestGenerateBinaryNameFromPath(t *testing.T) {
|
|||
assert.Equal(t, "Test Script", GenerateBinaryNameFromPath(".test-script"))
|
||||
assert.Equal(t, "Browser Broker", GenerateBinaryNameFromPath("browser_broker.exe"))
|
||||
assert.Equal(t, "Virtual Box VM", GenerateBinaryNameFromPath("VirtualBoxVM"))
|
||||
assert.Equal(t, "Io Elementary Appcenter", GenerateBinaryNameFromPath("io.elementary.appcenter"))
|
||||
}
|
||||
|
||||
func TestCleanFileDescription(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
assert.Equal(t, "Product Name", cleanFileDescription("Product Name. Does this and that."))
|
||||
assert.Equal(t, "Product Name", cleanFileDescription("Product Name - Does this and that."))
|
||||
assert.Equal(t, "Product Name", cleanFileDescription("Product Name / Does this and that."))
|
||||
|
|
Loading…
Add table
Reference in a new issue