diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-08-12 23:28:35 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-12 15:28:35 +0000 |
commit | bcccf4c0d6149e5e7382226a191abd54848f9416 (patch) | |
tree | b837d0ccd708f80dd33ce69e54ac87394bc7e0b9 /modules/setting/config_env.go | |
parent | 2eb456dde21b51be4cfeb185193cdcfd2a66f315 (diff) | |
download | gitea-bcccf4c0d6149e5e7382226a191abd54848f9416.tar.gz gitea-bcccf4c0d6149e5e7382226a191abd54848f9416.zip |
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>
Diffstat (limited to 'modules/setting/config_env.go')
-rw-r--r-- | modules/setting/config_env.go | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/modules/setting/config_env.go b/modules/setting/config_env.go index bd479253dc..b30e44de30 100644 --- a/modules/setting/config_env.go +++ b/modules/setting/config_env.go @@ -4,6 +4,7 @@ package setting import ( + "bytes" "os" "regexp" "strconv" @@ -131,6 +132,11 @@ func EnvironmentToConfig(cfg ConfigProvider, envs []string) (changed bool) { log.Error("Error reading file for %s : %v", envKey, envValue, err) continue } + if bytes.HasSuffix(fileContent, []byte("\r\n")) { + fileContent = fileContent[:len(fileContent)-2] + } else if bytes.HasSuffix(fileContent, []byte("\n")) { + fileContent = fileContent[:len(fileContent)-1] + } keyValue = string(fileContent) } |