From 29e2c2fa92b10c1250376913558448e838e390fe Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 22 Oct 2025 12:13:02 +0200 Subject: [PATCH] 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 --- parser/metadecoders/decoder_integration_test.go | 1 + tpl/compare/compare.go | 4 ++-- tpl/compare/compare_test.go | 5 +++++ 3 files changed, 8 insertions(+), 2 deletions(-) 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}, -- 2.39.5