Trim string slices upon loading config (fixes #1750)

This commit is contained in:
Audrius Butkevicius 2015-06-25 16:48:41 +01:00
parent 824fa8f17a
commit dae1d36a23
3 changed files with 32 additions and 1 deletions

View File

@ -578,7 +578,7 @@ func fillNilSlices(data interface{}) error {
func uniqueStrings(ss []string) []string {
var m = make(map[string]bool, len(ss))
for _, s := range ss {
m[s] = true
m[strings.Trim(s, " ")] = true
}
var us = make([]string, 0, len(m))

View File

@ -317,6 +317,29 @@ func TestIssue1262(t *testing.T) {
}
}
func TestIssue1750(t *testing.T) {
cfg, err := Load("testdata/issue-1750.xml", device4)
if err != nil {
t.Fatal(err)
}
if cfg.Options().ListenAddress[0] != ":23000" {
t.Errorf("%q != %q", cfg.Options().ListenAddress[0], ":23000")
}
if cfg.Options().ListenAddress[1] != ":23001" {
t.Errorf("%q != %q", cfg.Options().ListenAddress[1], ":23001")
}
if cfg.Options().GlobalAnnServers[0] != "udp4://syncthing.nym.se:22026" {
t.Errorf("%q != %q", cfg.Options().GlobalAnnServers[0], "udp4://syncthing.nym.se:22026")
}
if cfg.Options().GlobalAnnServers[1] != "udp4://syncthing.nym.se:22027" {
t.Errorf("%q != %q", cfg.Options().GlobalAnnServers[1], "udp4://syncthing.nym.se:22027")
}
}
func TestWindowsPaths(t *testing.T) {
if runtime.GOOS != "windows" {
t.Skip("Not useful on non-Windows")

View File

@ -0,0 +1,8 @@
<configuration version="9">
<options>
<listenAddress> :23000</listenAddress>
<listenAddress> :23001 </listenAddress>
<globalAnnounceServer> udp4://syncthing.nym.se:22026</globalAnnounceServer>
<globalAnnounceServer> udp4://syncthing.nym.se:22027 </globalAnnounceServer>
</options>
</configuration>