aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-09-11 00:15:51 +0800
committerGitHub <noreply@github.com>2023-09-10 16:15:51 +0000
commite7745c94f8ca78d4c7892968ca1a1b00326a7bbd (patch)
tree8f9daef4c4456e017842b384de4b0fdc8199a282
parentde68953bac232bba4d74f9576ef941753dcb2131 (diff)
downloadgitea-e7745c94f8ca78d4c7892968ca1a1b00326a7bbd.tar.gz
gitea-e7745c94f8ca78d4c7892968ca1a1b00326a7bbd.zip
Fix INI parsing for value with trailing slash (#26995)
Fix #26977 (a temp fix)
-rw-r--r--modules/setting/config_provider.go12
-rw-r--r--modules/setting/config_provider_test.go10
2 files changed, 20 insertions, 2 deletions
diff --git a/modules/setting/config_provider.go b/modules/setting/config_provider.go
index d00164df9e..8d64286288 100644
--- a/modules/setting/config_provider.go
+++ b/modules/setting/config_provider.go
@@ -174,9 +174,16 @@ func (s *iniConfigSection) ChildSections() (sections []ConfigSection) {
return sections
}
+func configProviderLoadOptions() ini.LoadOptions {
+ return ini.LoadOptions{
+ KeyValueDelimiterOnWrite: " = ",
+ IgnoreContinuation: true,
+ }
+}
+
// NewConfigProviderFromData this function is mainly for testing purpose
func NewConfigProviderFromData(configContent string) (ConfigProvider, error) {
- cfg, err := ini.Load(strings.NewReader(configContent))
+ cfg, err := ini.LoadSources(configProviderLoadOptions(), strings.NewReader(configContent))
if err != nil {
return nil, err
}
@@ -190,7 +197,7 @@ func NewConfigProviderFromData(configContent string) (ConfigProvider, error) {
// NewConfigProviderFromFile load configuration from file.
// NOTE: do not print any log except error.
func NewConfigProviderFromFile(file string, extraConfigs ...string) (ConfigProvider, error) {
- cfg := ini.Empty(ini.LoadOptions{KeyValueDelimiterOnWrite: " = "})
+ cfg := ini.Empty(configProviderLoadOptions())
loadedFromEmpty := true
if file != "" {
@@ -339,6 +346,7 @@ func NewConfigProviderForLocale(source any, others ...any) (ConfigProvider, erro
iniFile, err := ini.LoadSources(ini.LoadOptions{
IgnoreInlineComment: true,
UnescapeValueCommentSymbols: true,
+ IgnoreContinuation: true,
}, source, others...)
if err != nil {
return nil, fmt.Errorf("unable to load locale ini: %w", err)
diff --git a/modules/setting/config_provider_test.go b/modules/setting/config_provider_test.go
index 7e7c6be2bb..a666d124c7 100644
--- a/modules/setting/config_provider_test.go
+++ b/modules/setting/config_provider_test.go
@@ -30,6 +30,16 @@ key = 123
secSub := cfg.Section("foo.bar.xxx")
assert.Equal(t, "123", secSub.Key("key").String())
})
+ t.Run("TrailingSlash", func(t *testing.T) {
+ cfg, _ := NewConfigProviderFromData(`
+[foo]
+key = E:\
+xxx = yyy
+`)
+ sec := cfg.Section("foo")
+ assert.Equal(t, "E:\\", sec.Key("key").String())
+ assert.Equal(t, "yyy", sec.Key("xxx").String())
+ })
}
func TestConfigProviderHelper(t *testing.T) {