From 53077b0da54906feee64a03612e5186043e17341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 1 Aug 2019 10:19:19 +0200 Subject: Merge pull request #6149 from bep/sort-caseinsensitive Implement lexicographically string sorting --- tpl/collections/sort.go | 8 ++++---- tpl/collections/sort_test.go | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'tpl/collections') diff --git a/tpl/collections/sort.go b/tpl/collections/sort.go index 1ab4409b6..9639fe1d0 100644 --- a/tpl/collections/sort.go +++ b/tpl/collections/sort.go @@ -23,7 +23,7 @@ import ( "github.com/spf13/cast" ) -var comp = compare.New() +var sortComp = compare.New(true) // Sort returns a sorted sequence. func (ns *Namespace) Sort(seq interface{}, args ...interface{}) (interface{}, error) { @@ -133,15 +133,15 @@ func (p pairList) Less(i, j int) bool { if iv.IsValid() { if jv.IsValid() { // can only call Interface() on valid reflect Values - return comp.Lt(iv.Interface(), jv.Interface()) + return sortComp.Lt(iv.Interface(), jv.Interface()) } // if j is invalid, test i against i's zero value - return comp.Lt(iv.Interface(), reflect.Zero(iv.Type())) + return sortComp.Lt(iv.Interface(), reflect.Zero(iv.Type())) } if jv.IsValid() { // if i is invalid, test j against j's zero value - return comp.Lt(reflect.Zero(jv.Type()), jv.Interface()) + return sortComp.Lt(reflect.Zero(jv.Type()), jv.Interface()) } return false diff --git a/tpl/collections/sort_test.go b/tpl/collections/sort_test.go index f5f291f0b..612a928cb 100644 --- a/tpl/collections/sort_test.go +++ b/tpl/collections/sort_test.go @@ -45,6 +45,7 @@ func TestSort(t *testing.T) { }{ {[]string{"class1", "class2", "class3"}, nil, "asc", []string{"class1", "class2", "class3"}}, {[]string{"class3", "class1", "class2"}, nil, "asc", []string{"class1", "class2", "class3"}}, + {[]string{"CLASS3", "class1", "class2"}, nil, "asc", []string{"class1", "class2", "CLASS3"}}, // Issue 6023 {stringsSlice{"class3", "class1", "class2"}, nil, "asc", stringsSlice{"class1", "class2", "class3"}}, -- cgit v1.2.3