fix "null" in project views (#1158)

Co-authored-by: kolaente <k@knt.li>
This commit is contained in:
Tobias
2025-07-22 19:43:04 +02:00
committed by GitHub
parent 5a406b2ecc
commit a31255707e
2 changed files with 49 additions and 0 deletions

View File

@@ -224,6 +224,11 @@ func convertFieldValue(fieldName string, value interface{}, isFloat bool) (inter
// Handle JSON fields (non-float)
switch v := value.(type) {
case string:
// Check if the string is "null" (case insensitive) and return nil for SQL NULL
if strings.ToLower(v) == "null" {
return nil, nil
}
decoded, err := base64.StdEncoding.DecodeString(v)
if err != nil {
var corruptErr base64.CorruptInputError

View File

@@ -80,6 +80,24 @@ func TestConvertFieldValue(t *testing.T) {
assert.JSONEq(t, jsonData, result.(string))
})
t.Run("should return nil for 'null' string", func(t *testing.T) {
result, err := convertFieldValue("bucket_configuration", "null", false)
require.NoError(t, err)
assert.Nil(t, result)
})
t.Run("should return nil for 'NULL' string", func(t *testing.T) {
result, err := convertFieldValue("bucket_configuration", "NULL", false)
require.NoError(t, err)
assert.Nil(t, result)
})
t.Run("should return nil for 'Null' string", func(t *testing.T) {
result, err := convertFieldValue("bucket_configuration", "Null", false)
require.NoError(t, err)
assert.Nil(t, result)
})
t.Run("should return error for non-string type", func(t *testing.T) {
_, err := convertFieldValue("permissions", 123, false)
require.Error(t, err)
@@ -105,4 +123,30 @@ func TestConvertFieldValue(t *testing.T) {
assert.Equal(t, invalidBase64, result)
})
})
t.Run("Edge cases", func(t *testing.T) {
t.Run("should handle empty string for JSON field", func(t *testing.T) {
result, err := convertFieldValue("permissions", "", false)
require.NoError(t, err)
assert.Empty(t, result)
})
t.Run("should handle empty string for float field", func(t *testing.T) {
_, err := convertFieldValue("position", "", true)
require.Error(t, err)
assert.Contains(t, err.Error(), "could not parse double value")
})
t.Run("should handle zero float value", func(t *testing.T) {
result, err := convertFieldValue("position", 0.0, true)
require.NoError(t, err)
assert.InDelta(t, 0.0, result, 0.0001)
})
t.Run("should handle negative float value", func(t *testing.T) {
result, err := convertFieldValue("position", -123.45, true)
require.NoError(t, err)
assert.InEpsilon(t, -123.45, result, 0.0001)
})
})
}