Skip to content

Commit

Permalink
fix multi-line strings not being parsed correctly in config.ini (#651)
Browse files Browse the repository at this point in the history
* fix multi-line strings not being parsed correctly in `config.ini`

* add tests
  • Loading branch information
umbynos committed Jul 15, 2021
1 parent b691425 commit d759c46
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
25 changes: 25 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 1 addition & 1 deletion systray/systray_real.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 9 additions & 0 deletions test/testdata/test.ini
Original file line number Diff line number Diff line change
@@ -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-----

0 comments on commit d759c46

Please sign in to comment.