Remove last newline from config file (#26468)
When users put the secrets into a file (GITEA__sec__KEY__FILE), the newline sometimes is different to avoid (eg: echo/vim/...) So the last newline could be removed when reading, it makes the users easier to maintain the secret files. Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
@ -99,4 +99,19 @@ key = old
|
||||
changed = EnvironmentToConfig(cfg, []string{"GITEA__sec__key__FILE=" + tmpFile})
|
||||
assert.True(t, changed)
|
||||
assert.Equal(t, "value-from-file", cfg.Section("sec").Key("key").String())
|
||||
|
||||
cfg, _ = NewConfigProviderFromData("")
|
||||
_ = os.WriteFile(tmpFile, []byte("value-from-file\n"), 0o644)
|
||||
EnvironmentToConfig(cfg, []string{"GITEA__sec__key__FILE=" + tmpFile})
|
||||
assert.Equal(t, "value-from-file", cfg.Section("sec").Key("key").String())
|
||||
|
||||
cfg, _ = NewConfigProviderFromData("")
|
||||
_ = os.WriteFile(tmpFile, []byte("value-from-file\r\n"), 0o644)
|
||||
EnvironmentToConfig(cfg, []string{"GITEA__sec__key__FILE=" + tmpFile})
|
||||
assert.Equal(t, "value-from-file", cfg.Section("sec").Key("key").String())
|
||||
|
||||
cfg, _ = NewConfigProviderFromData("")
|
||||
_ = os.WriteFile(tmpFile, []byte("value-from-file\n\n"), 0o644)
|
||||
EnvironmentToConfig(cfg, []string{"GITEA__sec__key__FILE=" + tmpFile})
|
||||
assert.Equal(t, "value-from-file\n", cfg.Section("sec").Key("key").String())
|
||||
}
|
||||
|
Reference in New Issue
Block a user