Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML Encode the windows XML data #3722

Merged
merged 3 commits into from
Mar 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions cmd/fyne/internal/commands/encode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package commands

import "strings"

func encodeXMLString(in string) string {
amped := strings.ReplaceAll(in, "&", "&")
return strings.ReplaceAll(strings.ReplaceAll(amped, "<", "&lt;"), ">", "&gt;")
Jacalz marked this conversation as resolved.
Show resolved Hide resolved
}
16 changes: 16 additions & 0 deletions cmd/fyne/internal/commands/encode_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package commands

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestEncodeXMLString(t *testing.T) {
assert.Equal(t, "", encodeXMLString(""))
assert.Equal(t, "Hello", encodeXMLString("Hello"))
assert.Equal(t, "Hi &amp; bye", encodeXMLString("Hi & bye"))
assert.Equal(t, "Hi &amp;amp; bye", encodeXMLString("Hi &amp; bye"))

assert.Equal(t, "Hi &lt;&gt; bye", encodeXMLString("Hi <> bye"))
}
4 changes: 2 additions & 2 deletions cmd/fyne/internal/commands/package-windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (p *Packager) packageWindows(tags []string) error {
return fmt.Errorf("failed to decode source image: %w", err)
}

icoPath := filepath.Join(exePath, p.Name+".ico")
icoPath := filepath.Join(exePath, "FyneApp.ico")
file, err := os.Create(icoPath)
if err != nil {
return fmt.Errorf("failed to open image file: %w", err)
Expand All @@ -59,7 +59,7 @@ func (p *Packager) packageWindows(tags []string) error {
manifestFile, _ := os.Create(manifest)

tplData := windowsData{
Name: p.Name,
Name: encodeXMLString(p.Name),
CombinedVersion: p.combinedVersion(),
}
err := templates.ManifestWindows.Execute(manifestFile, tplData)
Expand Down
6 changes: 3 additions & 3 deletions cmd/fyne/internal/commands/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,9 @@ func (r *Releaser) packageWindowsRelease(outFile string) error {
manifestData := struct{ AppID, Developer, DeveloperName, Name, Version string }{
AppID: r.AppID,
// TODO read this info
Developer: r.developer,
DeveloperName: r.nameFromCertInfo(r.developer),
Name: r.Name,
Developer: encodeXMLString(r.developer),
DeveloperName: encodeXMLString(r.nameFromCertInfo(r.developer)),
Name: encodeXMLString(r.Name),
Version: r.combinedVersion(),
}
err = templates.AppxManifestWindows.Execute(manifest, manifestData)
Expand Down