From: Bjørn Erik Pedersen Date: Wed, 22 Oct 2025 10:13:02 +0000 (+0200) Subject: tpl/compare: Fix compare/sort of uint64s X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=29e2c2fa92b10c1250376913558448e838e390fe;p=brevno-suite%2Fhugo tpl/compare: Fix compare/sort of uint64s `uint64` is used by github.com/goccy/go-yaml for unsigned integers, which is the reason why this long-living bug has surfaced now. Fixes #14078 --- diff --git a/parser/metadecoders/decoder_integration_test.go b/parser/metadecoders/decoder_integration_test.go index 2e533c5e4..9c8a15e89 100644 --- a/parser/metadecoders/decoder_integration_test.go +++ b/parser/metadecoders/decoder_integration_test.go @@ -33,6 +33,7 @@ t: -- layouts/all.html -- {{ $mydata := resources.Get "mydata.yaml" | transform.Unmarshal }} +Type: {{ printf "%T" $mydata.a.weight }}| Sorted: {{ sort $mydata "weight" }}| ` diff --git a/tpl/compare/compare.go b/tpl/compare/compare.go index d32f3df95..c5eaa87f5 100644 --- a/tpl/compare/compare.go +++ b/tpl/compare/compare.go @@ -244,11 +244,11 @@ func (ns *Namespace) compareGet(a any, b any) (float64, float64) { func (ns *Namespace) compareTwoUints(a uint64, b uint64) (float64, float64) { if a < b { - return 1, 0 + return 0, 1 } else if a == b { return 0, 0 } else { - return 0, 1 + return 1, 0 } } diff --git a/tpl/compare/compare_test.go b/tpl/compare/compare_test.go index 0ebebef4b..c55322fe3 100644 --- a/tpl/compare/compare_test.go +++ b/tpl/compare/compare_test.go @@ -207,6 +207,11 @@ func doTestCompare(t *testing.T, tp tstCompareType, funcUnderTest func(a, b any) {uint32(4), uint16(3), 1}, {uint64(4), 4, 0}, {4, uint64(4), 0}, + {uint64(4), 5, -1}, + {5, uint64(4), 1}, + {uint64(5), uint64(4), 1}, + {uint64(4), uint64(5), -1}, + {uint64(5), uint64(5), 0}, {uint64(math.MaxUint32), uint32(math.MaxUint32), 0}, {uint64(math.MaxUint16), int(math.MaxUint16), 0}, {int16(4), int(5), -1},