Skip to content

Commit 16cce71

Browse files
committed
fix(reflect): sort integers as integers rather than strings
1 parent 7891132 commit 16cce71

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

internal/template/sort.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ func getFieldAsString(item interface{}, path string) string {
9090
func (s sortableByKey) Less(i, j int) bool {
9191
dataI := getFieldAsString(s.data[i], s.key)
9292
dataJ := getFieldAsString(s.data[j], s.key)
93+
94+
if intI, errI := strconv.ParseInt(dataI, 10, 64); errI == nil {
95+
if intJ, errJ := strconv.ParseInt(dataJ, 10, 64); errJ == nil {
96+
// If both are integers, compare as integers
97+
return intI < intJ
98+
}
99+
}
100+
93101
return dataI < dataJ
94102
}
95103

0 commit comments

Comments
 (0)