aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--conf/parser.go19
-rw-r--r--conf/store.go4
-rw-r--r--go.mod1
-rw-r--r--ui/tunnelspage.go2
4 files changed, 23 insertions, 3 deletions
diff --git a/conf/parser.go b/conf/parser.go
index e98a0244..88802688 100644
--- a/conf/parser.go
+++ b/conf/parser.go
@@ -13,6 +13,8 @@ import (
"strconv"
"strings"
"time"
+
+ "golang.org/x/text/encoding/unicode"
)
type ParseError struct {
@@ -338,6 +340,23 @@ func FromWgQuick(s string, name string) (*Config, error) {
return &conf, nil
}
+func FromWgQuickWithUnknownEncoding(s string, name string) (*Config, error) {
+ c, firstErr := FromWgQuick(s, name)
+ if firstErr == nil {
+ return c, nil
+ }
+ for _, encoding := range unicode.All {
+ decoded, err := encoding.NewDecoder().String(s)
+ if err == nil {
+ c, err := FromWgQuick(decoded, name)
+ if err == nil {
+ return c, nil
+ }
+ }
+ }
+ return nil, firstErr
+}
+
func FromUAPI(s string, existingConfig *Config) (*Config, error) {
lines := strings.Split(s, "\n")
parserState := inInterfaceSection
diff --git a/conf/store.go b/conf/store.go
index 9c645a6b..2886d027 100644
--- a/conf/store.go
+++ b/conf/store.go
@@ -84,7 +84,7 @@ func MigrateUnencryptedConfigs() (int, []error) {
e++
continue
}
- _, err = FromWgQuick(string(bytes), "input")
+ _, err = FromWgQuickWithUnknownEncoding(string(bytes), "input")
if err != nil {
errs[e] = err
e++
@@ -143,7 +143,7 @@ func LoadFromPath(path string) (*Config, error) {
return nil, err
}
}
- return FromWgQuick(string(bytes), name)
+ return FromWgQuickWithUnknownEncoding(string(bytes), name)
}
func NameFromPath(path string) (string, error) {
diff --git a/go.mod b/go.mod
index dde9fd0f..b261fb42 100644
--- a/go.mod
+++ b/go.mod
@@ -7,6 +7,7 @@ require (
golang.org/x/crypto latest
golang.org/x/net latest
golang.org/x/sys latest
+ golang.org/x/text v0.3.0
github.com/Microsoft/go-winio latest
github.com/lxn/walk latest
diff --git a/ui/tunnelspage.go b/ui/tunnelspage.go
index 847036fe..3c60b728 100644
--- a/ui/tunnelspage.go
+++ b/ui/tunnelspage.go
@@ -332,7 +332,7 @@ func (tp *TunnelsPage) importFiles(paths []string) {
lastErr = fmt.Errorf("Another tunnel already exists with the name ā€˜%sā€™", unparsedConfig.Name)
continue
}
- config, err := conf.FromWgQuick(unparsedConfig.Config, unparsedConfig.Name)
+ config, err := conf.FromWgQuickWithUnknownEncoding(unparsedConfig.Config, unparsedConfig.Name)
if err != nil {
lastErr = err
continue