]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix where with uint64
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 22 Oct 2025 16:29:40 +0000 (18:29 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 22 Oct 2025 19:04:39 +0000 (21:04 +0200)
Fixes #14081

parser/metadecoders/decoder_integration_test.go
tpl/collections/where.go
tpl/collections/where_test.go

index 9c8a15e8909f2f4693c95bf83e72339bfa8bc5c7..9da1ee17db7169e94f46242b1604085ae738bca4 100644 (file)
@@ -42,3 +42,38 @@ Sorted: {{ sort $mydata "weight" }}|
 
        b.AssertFileContent("public/index.html", "Sorted: [map[weight:1] map[weight:2] map[weight:3] map[weight:4]]|")
 }
+
+func TestYAMLIntegerWhere(t *testing.T) {
+       files := `
+-- assets/mydata.yaml --
+a:
+   weight: 1
+x:
+  weight: 2
+c:
+  weight: 3
+t:
+  weight: 4
+-- assets/myslice.yaml --
+- weight: 1
+  name: one
+- weight: 2
+  name: two
+- weight: 3
+  name: three
+- weight: 4
+  name: four
+
+-- layouts/all.html --
+{{ $mydata1 := resources.Get "mydata.yaml" | transform.Unmarshal }}
+{{ $myslice := resources.Get "myslice.yaml" | transform.Unmarshal }}
+{{ $filtered := where $myslice "weight" "ge" $mydata1.x.weight }}
+mydata1: {{ $mydata1 }}|
+Filtered: {{ $filtered }}|
+
+`
+
+       b := hugolib.Test(t, files)
+
+       b.AssertFileContent("public/index.html", "[map[name:two weight:2] map[name:three weight:3] map[name:four weight:4]]|")
+}
index ee49d0bbbed4e05b58b18b663dfc556021e98941..34bfa057a656bf3a66d15b9b66ff9e5579d4ca10 100644 (file)
@@ -100,6 +100,11 @@ func (ns *Namespace) checkCondition(v, mv reflect.Value, op string) (bool, error
                        ivp = &iv
                        imv := mv.Int()
                        imvp = &imv
+               case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
+                       iv := int64(v.Uint())
+                       ivp = &iv
+                       imv := int64(mv.Uint())
+                       imvp = &imv
                case reflect.String:
                        sv := v.String()
                        svp = &sv
@@ -495,6 +500,8 @@ func toFloat(v reflect.Value) (float64, error) {
                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.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
+               return v.Convert(reflect.TypeOf(float64(0))).Float(), nil
        case reflect.Interface:
                return toFloat(v.Elem())
        }
index ecf748f936f4f023684d2d789795ea10a5f6043b..9d441b0309c309a664378ba37155733780f96d95 100644 (file)
@@ -23,6 +23,7 @@ import (
        "testing"
        "time"
 
+       qt "github.com/frankban/quicktest"
        "github.com/gohugoio/hugo/common/maps"
 )
 
@@ -862,6 +863,32 @@ func TestEvaluateSubElem(t *testing.T) {
        }
 }
 
+func TestToFloat(t *testing.T) {
+       t.Parallel()
+
+       c := qt.New(t)
+
+       to := func(v any) float64 {
+               f, err := toFloat(reflect.ValueOf(v))
+               c.Assert(err, qt.IsNil)
+               return f
+       }
+
+       c.Assert(to(uint64(32)), qt.Equals, 32.0)
+       c.Assert(to(int64(32)), qt.Equals, 32.0)
+       c.Assert(to(uint32(32)), qt.Equals, 32.0)
+       c.Assert(to(int32(32)), qt.Equals, 32.0)
+
+       c.Assert(to(uint16(32)), qt.Equals, 32.0)
+       c.Assert(to(int16(32)), qt.Equals, 32.0)
+
+       c.Assert(to(uint8(32)), qt.Equals, 32.0)
+       c.Assert(to(int8(32)), qt.Equals, 32.0)
+
+       c.Assert(to(uint(32)), qt.Equals, 32.0)
+       c.Assert(to(int(32)), qt.Equals, 32.0)
+}
+
 func BenchmarkWhereOps(b *testing.B) {
        ns := newNs()
        var seq []map[string]string