Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion v2/pkg/buildassets/build/darwin/Info.dev.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<key>CFBundleExecutable</key>
<string>{{.OutputFilename}}</string>
<key>CFBundleIdentifier</key>
<string>com.wails.{{.Name}}</string>
<string>com.wails.{{safeBundleID .Name}}</string>
<key>CFBundleVersion</key>
<string>{{.Info.ProductVersion}}</string>
<key>CFBundleGetInfoString</key>
Expand Down
2 changes: 1 addition & 1 deletion v2/pkg/buildassets/build/darwin/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<key>CFBundleExecutable</key>
<string>{{.OutputFilename}}</string>
<key>CFBundleIdentifier</key>
<string>com.wails.{{.Name}}</string>
<string>com.wails.{{safeBundleID .Name}}</string>
<key>CFBundleVersion</key>
<string>{{.Info.ProductVersion}}</string>
<key>CFBundleGetInfoString</key>
Expand Down
22 changes: 21 additions & 1 deletion v2/pkg/buildassets/buildassets.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
iofs "io/fs"
"os"
"path/filepath"
"regexp"
"strings"
"text/template"

"github.com/leaanthony/gosod"
Expand Down Expand Up @@ -107,8 +109,26 @@ type assetData struct {
OutputFilename string
}

func xmlEscape(s string) string {
var buf bytes.Buffer
template.HTMLEscape(&buf, []byte(s))
return buf.String()
}

var nonAlphaNum = regexp.MustCompile(`[^A-Za-z0-9]+`)

func safeBundleID(s string) string {
result := strings.ToLower(nonAlphaNum.ReplaceAllString(s, "-"))
result = strings.Trim(result, "-")
return result
}

func resolveProjectData(content []byte, projectData *project.Project) ([]byte, error) {
tmpl, err := template.New("").Parse(string(content))
funcMap := template.FuncMap{
"xml": xmlEscape,
"safeBundleID": safeBundleID,
}
tmpl, err := template.New("").Funcs(funcMap).Parse(string(content))
if err != nil {
return nil, err
}
Expand Down
27 changes: 27 additions & 0 deletions v2/pkg/buildassets/safebundleid_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package buildassets

import (
"testing"
)

func TestSafeBundleID(t *testing.T) {
tests := []struct {
input string
expected string
}{
{"My Fab Application", "my-fab-application"},
{"SimpleApp", "simpleapp"},
{"App-With-Dashes", "app-with-dashes"},
{"App_With_Underscores", "app-with-underscores"},
{"App@#$%^&*()", "app"},
{"123App", "123app"},
{" Spaces ", "spaces"},
{"already-lowercase", "already-lowercase"},
}
for _, tt := range tests {
got := safeBundleID(tt.input)
if got != tt.expected {
t.Errorf("safeBundleID(%q) = %q, want %q", tt.input, got, tt.expected)
}
}
}
Loading