Skip to content

fix: sort and sort_by error on maps and arrays with undefined ordering - #2940

Open
johnhldiver-beep wants to merge 1 commit into
mikefarah:masterfrom
johnhldiver-beep:fix/yq-2884-sort-uncomparable
Open

johnhldiver-beep wants to merge 1 commit into
mikefarah:masterfrom
johnhldiver-beep:fix/yq-2884-sort-uncomparable

Conversation

@johnhldiver-beep

Copy link
Copy Markdown

Fixes #2884.

Problem: sort and sort_by silently accept values with undefined ordering, while max correctly errors. For example, yq -n '[{"a":1},{"a":0}] | sort' silently returned the input unsorted, and the same happened for arrays (map([.a]) | sort) and for sort_by(exp) when the expression evaluates to an array or object.

Change: sort and sort_by now return a clear error when a comparison key is a map or array (or any value the comparison logic cannot order), matching max behavior. Ordering of numbers, strings, booleans, and nulls is unchanged. Tests: 4 new scenarios in operator_sort_test.go.

Verification: go build ./... passes; TestSortByOperatorScenarios passes. Note: TestJSONScenarios fails on this branch and also on upstream master (pre-existing, Go-version-dependent JSON error wording), unrelated to this change.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sort and sort_by silently accept types with undefined ordering

1 participant