From d759c46e7909c0d60114e0b4f21173f0f4e38902 Mon Sep 17 00:00:00 2001 From: Umberto Baldi <34278123+umbynos@users.noreply.github.com> Date: Wed, 14 Jul 2021 17:59:46 +0200 Subject: [PATCH] fix multi-line strings not being parsed correctly in `config.ini` (#651) * fix multi-line strings not being parsed correctly in `config.ini` * add tests --- main.go | 2 +- main_test.go | 25 +++++++++++++++++++++++++ systray/systray_real.go | 2 +- test/testdata/test.ini | 9 +++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 main_test.go create mode 100644 test/testdata/test.ini diff --git a/main.go b/main.go index bdfa8af87..db0ab47d2 100755 --- a/main.go +++ b/main.go @@ -644,7 +644,7 @@ body { ` func parseIni(filename string) (args []string, err error) { - cfg, err := ini.LoadSources(ini.LoadOptions{IgnoreInlineComment: false}, filename) + cfg, err := ini.LoadSources(ini.LoadOptions{IgnoreInlineComment: false, AllowPythonMultilineValues: true}, filename) if err != nil { return nil, err } diff --git a/main_test.go b/main_test.go new file mode 100644 index 000000000..2bd292562 --- /dev/null +++ b/main_test.go @@ -0,0 +1,25 @@ +package main + +import ( + "crypto/x509" + "encoding/pem" + "path/filepath" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestValidSignatureKey(t *testing.T) { + testfile := filepath.Join("test", "testdata", "test.ini") + args, err := parseIni(testfile) + require.NoError(t, err) + require.NotNil(t, args) + err = iniConf.Parse(args) + require.NoError(t, err) + print(*signatureKey) + block, _ := pem.Decode([]byte(*signatureKey)) + require.NotNil(t, block) + key, err := x509.ParsePKIXPublicKey(block.Bytes) + require.NoError(t, err) + require.NotNil(t, key) +} diff --git a/systray/systray_real.go b/systray/systray_real.go index 9c7d5d4bc..de8a50cc1 100644 --- a/systray/systray_real.go +++ b/systray/systray_real.go @@ -182,7 +182,7 @@ func getConfigs() []configIni { err := filepath.Walk(dest, func(path string, f os.FileInfo, _ error) error { if !f.IsDir() { if filepath.Ext(path) == ".ini" { - cfg, err := ini.LoadSources(ini.LoadOptions{IgnoreInlineComment: true}, filepath.Join(dest, f.Name())) + cfg, err := ini.LoadSources(ini.LoadOptions{IgnoreInlineComment: true, AllowPythonMultilineValues: true}, filepath.Join(dest, f.Name())) if err != nil { return err } diff --git a/test/testdata/test.ini b/test/testdata/test.ini new file mode 100644 index 000000000..c9629a110 --- /dev/null +++ b/test/testdata/test.ini @@ -0,0 +1,9 @@ +signatureKey = -----BEGIN PUBLIC KEY----- + MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvc0yZr1yUSen7qmE3cxF + IE12rCksDnqR+Hp7o0nGi9123eCSFcJ7CkIRC8F+8JMhgI3zNqn4cUEn47I3RKD1 + ZChPUCMiJCvbLbloxfdJrUi7gcSgUXrlKQStOKF5Iz7xv1M4XOP3JtjXLGo3EnJ1 + pFgdWTOyoSrA8/w1rck4c/ISXZSinVAggPxmLwVEAAln6Itj6giIZHKvA2fL2o8z + CeK057Lu8X6u2CG8tRWSQzVoKIQw/PKK6CNXCAy8vo4EkXudRutnEYHEJlPkVgPn + 2qP06GI+I+9zKE37iqj0k1/wFaCVXHXIvn06YrmjQw6I0dDj/60Wvi500FuRVpn9 + twIDAQAB + -----END PUBLIC KEY-----