lang/funcs: in "sort", don't panic if given a null string

It is incorrect to use a null string, but that should be reported as an
error rather than a panic.
This commit is contained in:
Martin Atkins 2018-09-10 12:58:33 -07:00
parent 030784eb97
commit efe631d9ec
1 changed files with 4 additions and 1 deletions

View File

@ -72,7 +72,10 @@ var SortFunc = function.New(&function.Spec{
list := make([]string, 0, listVal.LengthInt())
for it := listVal.ElementIterator(); it.Next(); {
_, v := it.Element()
iv, v := it.Element()
if v.IsNull() {
return cty.UnknownVal(retType), fmt.Errorf("given list element %s is null; a null string cannot be sorted", iv.AsBigFloat().String())
}
list = append(list, v.AsString())
}