Repository navigation
fix(jmespath): return null for ordering non-numbers and reject mixed types - #5967
Merged
Merged
Conversation
…types Ordering comparators returned undefined when an operand wasn't a number. sort(), max() and min() accepted arrays whose leading elements didn't match the expected type, and sort_by(), max_by() and min_by() accepted keys that mixed numbers and strings. Fixes #5966
svozza
reviewed
Nov 16, 2026
dreamorosi
enabled auto-merge (squash)
November 16, 2026 15:43
dreamorosi
disabled auto-merge
November 16, 2026 15:43
typeCheckSortKeys now asserts that every visited key is a number or a string, so max_by, min_by and sort_by no longer need to cast them.
dreamorosi
requested review from
svozza
and removed request for
leandrodamascena
November 16, 2026 15:52
svozza
approved these changes
Nov 16, 2026
dreamorosi
enabled auto-merge (squash)
November 16, 2026 22:37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ordering comparators returned
undefinedwhen an operand wasn't a number, and that value broke the rest of the expression.sort(),max(),min(),sort_by(),max_by()andmin_by()also accepted mixed-type input that the JMESPath specification rejects. They now returnnullor throwJMESPathTypeError, as the specification says.Changes
<,<=,>and>=returnnullunless both operands are numbers (TreeInterpreter.ts). This follows the specification, which allows ordering only on numbers. Strings returnnulltoo:'a' < 'b'returnedundefinedbefore and now returnsnull.jmespath.pycompares strings here as an extension to the specification, and this change doesn't.sort(),max()andmin()check every element of the array and throw when the array mixes types or holds something other than numbers or strings (utils.ts). Before, leading elements that didn't match were skipped, sosort(['b', 1])andmax([null])succeeded. The error now lists both accepted types (expected one of "array-number", "array-string" but found "array") instead of naming the type of whichever element failed last.sort_by(),max_by()andmin_by()throw when the expression returns a mix of numbers and strings. A newtypeCheckSortKeyshelper inutils.tsreplaces the per-element check each function had.sort_by(people, &name)expected a sorted result. The upstreamfunctions.jsonexpectsinvalid-type, so the test now expects an error. The threemax/min/sorterror messages in the compliance tests were updated to the new wording.index.test.tshas new tests for every case in the issue. 23 of them fail onmain.v8 ignore elsecomment that kept the missing return out of coverage.Issue number: closes #5966
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.