mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-01 14:14:52 +08:00
fix(sort): avoid int64 overflow comparing large integers (#2771)
The int/int comparator returned int(lhs - rhs); the int64 subtraction overflows for large-magnitude values, giving the wrong sign. Compare directly instead. Co-authored-by: max <max@example.com>
This commit is contained in:
@@ -171,6 +171,15 @@ var sortByOperatorScenarios = []expressionScenario{
|
||||
"D0, P[], (!!seq)::# abc\n- def\n# ghi\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
description: "Sort large integers (no int64 subtraction overflow)",
|
||||
document: "[5000000000000000000, -5000000000000000000]",
|
||||
expression: `sort`,
|
||||
expected: []string{
|
||||
"D0, P[], (!!seq)::[-5000000000000000000, 5000000000000000000]\n",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestSortByOperatorScenarios(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user