Skip to content

Commit da7d7e6

Browse files
GiteaBotwxiaoguang
andauthored
Fix INI parsing for value with trailing slash (#26995) (#27001)
Backport #26995 by @wxiaoguang Fix #26977 (a temp fix) Co-authored-by: wxiaoguang <[email protected]>
1 parent e502be4 commit da7d7e6

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
@@ -174,9 +174,16 @@ func (s *iniConfigSection) ChildSections() (sections []ConfigSection) {
174174
return sections
175175
}
176176

177+
func configProviderLoadOptions() ini.LoadOptions {
178+
return ini.LoadOptions{
179+
KeyValueDelimiterOnWrite: " = ",
180+
IgnoreContinuation: true,
181+
}
182+
}
183+
177184
// NewConfigProviderFromData this function is mainly for testing purpose
178185
func NewConfigProviderFromData(configContent string) (ConfigProvider, error) {
179-
cfg, err := ini.Load(strings.NewReader(configContent))
186+
cfg, err := ini.LoadSources(configProviderLoadOptions(), strings.NewReader(configContent))
180187
if err != nil {
181188
return nil, err
182189
}
@@ -190,7 +197,7 @@ func NewConfigProviderFromData(configContent string) (ConfigProvider, error) {
190197
// NewConfigProviderFromFile load configuration from file.
191198
// NOTE: do not print any log except error.
192199
func NewConfigProviderFromFile(file string, extraConfigs ...string) (ConfigProvider, error) {
193-
cfg := ini.Empty(ini.LoadOptions{KeyValueDelimiterOnWrite: " = "})
200+
cfg := ini.Empty(configProviderLoadOptions())
194201
loadedFromEmpty := true
195202

196203
if file != "" {
@@ -339,6 +346,7 @@ func NewConfigProviderForLocale(source any, others ...any) (ConfigProvider, erro
339346
iniFile, err := ini.LoadSources(ini.LoadOptions{
340347
IgnoreInlineComment: true,
341348
UnescapeValueCommentSymbols: true,
349+
IgnoreContinuation: true,
342350
}, source, others...)
343351
if err != nil {
344352
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)