mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-30 22:39:58 +02:00
tpl/collections: Convert numeric values to float64 and compare them
Fixes #5685
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
4c560020bc
commit
fb007e9ae5
@@ -114,6 +114,17 @@ func (ns *Namespace) checkCondition(v, mv reflect.Value, op string) (bool, error
|
||||
slv = v.Interface()
|
||||
slmv = mv.Interface()
|
||||
}
|
||||
} else if isNumber(v.Kind()) && isNumber(mv.Kind()) {
|
||||
fv, err := toFloat(v)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
fvp = &fv
|
||||
fmv, err := toFloat(mv)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
fmvp = &fmv
|
||||
} else {
|
||||
if mv.Kind() != reflect.Array && mv.Kind() != reflect.Slice {
|
||||
return false, nil
|
||||
@@ -426,6 +437,8 @@ func toFloat(v reflect.Value) (float64, error) {
|
||||
switch v.Kind() {
|
||||
case reflect.Float32, reflect.Float64:
|
||||
return v.Float(), nil
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return v.Convert(reflect.TypeOf(float64(0))).Float(), nil
|
||||
case reflect.Interface:
|
||||
return toFloat(v.Elem())
|
||||
}
|
||||
|
Reference in New Issue
Block a user