mirror of
https://github.com/go-gitea/gitea
synced 2025-07-12 13:37:20 +00:00
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:
@ -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)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user