From 683add3ccfef2582ab4e381a8e37e2297a2067a6 Mon Sep 17 00:00:00 2001 From: Jason Ertel Date: Thu, 3 Aug 2023 12:22:43 -0400 Subject: [PATCH 1/2] list settings with blank strings will store as empty lists --- server/modules/salt/saltstore.go | 5 +++- server/modules/salt/saltstore_test.go | 37 ++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/server/modules/salt/saltstore.go b/server/modules/salt/saltstore.go index 3ee67020c..9f81dbd17 100644 --- a/server/modules/salt/saltstore.go +++ b/server/modules/salt/saltstore.go @@ -833,7 +833,10 @@ func (store *Saltstore) forceType(newValue string, forcedType string) (interface case "[]float": return store.alignFloat64List(newValue) case "[]string": - return strings.Split(newValue, "\n"), nil + if len(newValue) > 0 { + return strings.Split(newValue, "\n"), nil + } + return make([]string, 0, 0), nil case "[][]": return store.alignListList(newValue) case "[]{}": diff --git a/server/modules/salt/saltstore_test.go b/server/modules/salt/saltstore_test.go index 8f069c105..a4a9ca216 100644 --- a/server/modules/salt/saltstore_test.go +++ b/server/modules/salt/saltstore_test.go @@ -996,6 +996,41 @@ func TestUpdateSetting_AlignNonStringListType(tester *testing.T) { assert.Equal(tester, "123\n456\n", updated_setting.Value) } +func TestUpdateSetting_AlignBlankStringListType(tester *testing.T) { + defer Cleanup() + salt := NewTestSalt() + + // default should be an empty list + settings, get_err := salt.GetSettings(ctx()) + assert.NoError(tester, get_err) + updated_setting := findSetting(settings, "myapp.empty_lists.list_str", "") + assert.Equal(tester, "", updated_setting.Value) + + // Update empty setting with non-blank value + setting := model.NewSetting("myapp.empty_lists.list_str") + setting.Value = "foo" + err := salt.UpdateSetting(ctx(), setting, false) + assert.NoError(tester, err) + + // should now contain non-blank value + settings, get_err = salt.GetSettings(ctx()) + assert.NoError(tester, get_err) + updated_setting = findSetting(settings, "myapp.empty_lists.list_str", "") + assert.Equal(tester, "foo\n", updated_setting.Value) + + // Update empty setting with empty lines value + setting = model.NewSetting("myapp.empty_lists.list_str") + setting.Value = "\n" + err = salt.UpdateSetting(ctx(), setting, false) + assert.NoError(tester, err) + + // should be an empty list again + settings, get_err = salt.GetSettings(ctx()) + assert.NoError(tester, get_err) + updated_setting = findSetting(settings, "myapp.empty_lists.list_str", "") + assert.Equal(tester, "", updated_setting.Value) +} + func TestRelPathFromId(tester *testing.T) { defer Cleanup() salt := NewTestSalt() @@ -1185,7 +1220,7 @@ func TestForceType(tester *testing.T) { {value: "true\nfalse", forcedType: "[]bool", expected: []bool{true, false}, errorString: ""}, {value: "blah", forcedType: "[]bool", expected: []bool{}, errorString: "invalid syntax"}, {value: "hello", forcedType: "string", expected: "hello", errorString: ""}, - {value: "hello", forcedType: "[]string", expected: []string{"hello"}, errorString: ""}, + {value: "", forcedType: "[]string", expected: []string{}, errorString: ""}, {value: "hello\nthere", forcedType: "[]string", expected: []string{"hello", "there"}, errorString: ""}, {value: "blah", forcedType: "[]string", expected: []string{"blah"}, errorString: ""}, {value: "[\"hello\"]", forcedType: "[][]", expected: [][]interface{}([][]interface{}{[]interface{}{"hello"}}), errorString: ""}, From 519ee2f14eb20d5682a4c52a8498dda27a9fbe0b Mon Sep 17 00:00:00 2001 From: Jason Ertel Date: Thu, 3 Aug 2023 12:30:01 -0400 Subject: [PATCH 2/2] fix raid status --- html/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/html/index.html b/html/index.html index 998720d60..cd63039ec 100644 --- a/html/index.html +++ b/html/index.html @@ -3069,13 +3069,13 @@

{{ i18n.gridEps }} {{ gridEps | formatCount }}

{{ i18n.nodeStatusRaid }} - + {{ i18n.featureRequiresAppliance }} fa-circle-question - +