mirror of
https://github.com/alireza0/s-ui.git
synced 2026-10-21 03:12:06 +00:00
Trim surrounding whitespace from settings before validation (#1229)
* TrimSpace * delete TrimSpace test
This commit is contained in:
parent
08807ac1a3
commit
1900fd937d
1 changed files with 8 additions and 0 deletions
|
|
@ -405,6 +405,10 @@ func (s *SettingService) SaveConfig(tx *gorm.DB, config json.RawMessage) error {
|
|||
return tx.Model(model.Setting{}).Where("key = ?", "config").Update("value", string(configs)).Error
|
||||
}
|
||||
|
||||
func normalizeSettingValue(value string) string {
|
||||
return strings.TrimSpace(value)
|
||||
}
|
||||
|
||||
func (s *SettingService) Save(tx *gorm.DB, data json.RawMessage) error {
|
||||
var err error
|
||||
var settings map[string]string
|
||||
|
|
@ -413,6 +417,10 @@ func (s *SettingService) Save(tx *gorm.DB, data json.RawMessage) error {
|
|||
return err
|
||||
}
|
||||
for key, obj := range settings {
|
||||
// Ignore accidental surrounding whitespace while preserving spaces
|
||||
// inside values such as certificate paths and URLs.
|
||||
obj = normalizeSettingValue(obj)
|
||||
|
||||
// Secure file existence check
|
||||
if obj != "" && (key == "webCertFile" ||
|
||||
key == "webKeyFile" ||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue