IAM: Log error when malformed json arrays are found in SSO configs (#99896)
This commit is contained in:
+13
-4
@@ -33,9 +33,18 @@ func stringsFallback(vals ...string) string {
|
||||
|
||||
// SplitString splits a string and returns a list of strings. It supports JSON list syntax and strings separated by commas or spaces.
|
||||
// It supports quoted strings with spaces, e.g. "foo bar", "baz".
|
||||
// It will return an empty list if it fails to parse the string.
|
||||
func SplitString(str string) []string {
|
||||
result, _ := SplitStringWithError(str)
|
||||
return result
|
||||
}
|
||||
|
||||
// SplitStringWithError splits a string and returns a list of strings. It supports JSON list syntax and strings separated by commas or spaces.
|
||||
// It supports quoted strings with spaces, e.g. "foo bar", "baz".
|
||||
// It returns an error if it cannot parse the string.
|
||||
func SplitStringWithError(str string) ([]string, error) {
|
||||
if len(str) == 0 {
|
||||
return []string{}
|
||||
return []string{}, nil
|
||||
}
|
||||
|
||||
// JSON list syntax support
|
||||
@@ -43,9 +52,9 @@ func SplitString(str string) []string {
|
||||
var res []string
|
||||
err := json.Unmarshal([]byte(str), &res)
|
||||
if err != nil {
|
||||
return []string{}
|
||||
return []string{}, fmt.Errorf("incorrect format: %s", str)
|
||||
}
|
||||
return res
|
||||
return res, nil
|
||||
}
|
||||
|
||||
matches := stringListItemMatcher.FindAllString(str, -1)
|
||||
@@ -55,7 +64,7 @@ func SplitString(str string) []string {
|
||||
result[i] = strings.Trim(match, "\"")
|
||||
}
|
||||
|
||||
return result
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetAgeString returns a string representing certain time from years to minutes.
|
||||
|
||||
Reference in New Issue
Block a user