Skip to content

fix(jmespath): avoid mutating arrays in sort and reverse - #5843

Merged
svozza merged 2 commits into
mainfrom
fix/jmespath-array-mutation
Oct 26, 2026
Merged

svozza merged 2 commits into
mainfrom
fix/jmespath-array-mutation

Conversation

@dreamorosi

Copy link
Copy Markdown
Contributor

Summary

JMESPath sort() and reverse() now return new arrays without reordering the caller's input. This prevents expression evaluation from changing Lambda events passed through Idempotency and Validation.

This replaces closed PR #5823, based on the fix and regression tests contributed by @unknownhackerworld.

Changes

  • Use toSorted() and toReversed(), as requested in the original review, while preserving the existing sorting comparators and string-reversal behavior.
  • Retain the contributor's regression tests for numeric sorting, string sorting, and numeric reversal.
  • Extend regression coverage to string-array reversal and verify that results are separate arrays.

Issue number: closes #5822


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.

Use toSorted and toReversed so expression evaluation leaves caller input unchanged.

Recover regression coverage from #5823 and extend it to reversed strings and array identity.

Fixes #5822
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/M PR between 30-99 LOC label Oct 25, 2026
@dreamorosi
dreamorosi marked this pull request as ready for review October 25, 2026 16:34
@dreamorosi
dreamorosi requested a review from svozza October 25, 2026 16:35
@svozza
svozza merged commit 7421e40 into main Oct 26, 2026
41 checks passed
@svozza
svozza deleted the fix/jmespath-array-mutation branch October 26, 2026 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M PR between 30-99 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: JMESPath sort() and reverse() mutate the input array, so search() reorders the event

2 participants