Skip to content

Commit 957a64d

Browse files
GiteaBotwxiaoguang
authored andcommitted
Fix INI parsing for value with trailing slash (go-gitea#26995) (go-gitea#27001)
Backport go-gitea#26995 by @wxiaoguang Fix go-gitea#26977 (a temp fix) Co-authored-by: wxiaoguang <[email protected]> (cherry picked from commit da7d7e6)
1 parent 56a17f3 commit 957a64d

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

modules/setting/config_provider.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,16 @@ func (s *iniConfigSection) ChildSections() (sections []ConfigSection) {
175175
return sections
176176
}
177177

178+
func configProviderLoadOptions() ini.LoadOptions {
179+
return ini.LoadOptions{
180+
KeyValueDelimiterOnWrite: " = ",
181+
IgnoreContinuation: true,
182+
}
183+
}
184+
178185
// NewConfigProviderFromData this function is mainly for testing purpose
179186
func NewConfigProviderFromData(configContent string) (ConfigProvider, error) {
180-
cfg, err := ini.Load(strings.NewReader(configContent))
187+
cfg, err := ini.LoadSources(configProviderLoadOptions(), strings.NewReader(configContent))
181188
if err != nil {
182189
return nil, err
183190
}
@@ -191,7 +198,7 @@ func NewConfigProviderFromData(configContent string) (ConfigProvider, error) {
191198
// NewConfigProviderFromFile load configuration from file.
192199
// NOTE: do not print any log except error.
193200
func NewConfigProviderFromFile(file string, extraConfigs ...string) (ConfigProvider, error) {
194-
cfg := ini.Empty(ini.LoadOptions{KeyValueDelimiterOnWrite: " = "})
201+
cfg := ini.Empty(configProviderLoadOptions())
195202
loadedFromEmpty := true
196203

197204
if file != "" {
@@ -344,6 +351,7 @@ func NewConfigProviderForLocale(source any, others ...any) (ConfigProvider, erro
344351
iniFile, err := ini.LoadSources(ini.LoadOptions{
345352
IgnoreInlineComment: true,
346353
UnescapeValueCommentSymbols: true,
354+
IgnoreContinuation: true,
347355
}, source, others...)
348356
if err != nil {
349357
return nil, fmt.Errorf("unable to load locale ini: %w", err)

modules/setting/config_provider_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ key = 123
3030
secSub := cfg.Section("foo.bar.xxx")
3131
assert.Equal(t, "123", secSub.Key("key").String())
3232
})
33+
t.Run("TrailingSlash", func(t *testing.T) {
34+
cfg, _ := NewConfigProviderFromData(`
35+
[foo]
36+
key = E:\
37+
xxx = yyy
38+
`)
39+
sec := cfg.Section("foo")
40+
assert.Equal(t, "E:\\", sec.Key("key").String())
41+
assert.Equal(t, "yyy", sec.Key("xxx").String())
42+
})
3343
}
3444

3545
func TestConfigProviderHelper(t *testing.T) {

0 commit comments

Comments
 (0)