Skip to content

MOD-21733: Reject non-integer JSON.ARRPOP index - #1724

Open
AvivDavid23 wants to merge 1 commit into
masterfrom
MOD-21733-arr-pop-non-numeric-index
Open

AvivDavid23 wants to merge 1 commit into
masterfrom
MOD-21733-arr-pop-non-numeric-index

Conversation

@AvivDavid23

@AvivDavid23 AvivDavid23 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1713 (MOD-21733)

Problem

When an explicit JSON.ARRPOP index was not an integer, it was treated as -1 and the last element was removed:

JSON.SET k $ '[10,20,30]'
JSON.ARRPOP k $ not-an-integer   ->  30
JSON.GET k $                     ->  [[10,20]]

Fix

json_arr_pop_command_impl used args.next_i64().unwrap_or(-1), which mapped both "no index" and "unparsable index" to -1. It now defaults to -1 only when the index is omitted, and propagates the parse error otherwise.

Note: a non-integer index now returns Couldn't parse as integer, and since arguments are parsed before the key is opened, this takes precedence over key/path errors.

Test plan

  • New flow test testArrPopNonIntegerIndex: not-an-integer, 1.5, '' rejected for $ and legacy . paths with document unchanged; omitted index still pops the last element
  • test_multi.py:testErrorMessage: replaced incidental "abc" index (relied on the old silent -1) with -1; assertions on key/path errors unchanged
  • QUICK=1 suite 376/376; cargo clippy / cargo fmt --check clean
  • CI green

Note

Low Risk
Small argument-parsing fix in one command with targeted tests; behavior change only for invalid explicit indexes.

Overview
JSON.ARRPOP no longer treats a bad index as -1 and pops the last element. Index parsing now follows the same pattern as JSON.ARRINDEX: default to -1 only when the argument is omitted, and return a parse error (Couldn't parse as integer) when a value is present but not a valid integer—before the key is opened.

Tests add testArrPopNonIntegerIndex (non-integer and empty index rejected for $ and .; document unchanged; omitted index still pops the last). test_multi.py ARRPOP error cases use -1 instead of "abc", which previously relied on the silent fallback.

Reviewed by Cursor Bugbot for commit 19d7319. Bugbot is set up for automated code reviews on this repo. Configure here.

A supplied index that failed to parse was treated as -1, so the command
popped the last element instead of erroring. Parse the index when present
and propagate the error; an omitted index still defaults to -1.
@codecov

codecov Bot commented Dec 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.13%. Comparing base (d219b62) to head (19d7319).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1724   +/-   ##
=======================================
  Coverage   88.13%   88.13%           
=======================================
  Files          18       18           
  Lines        6861     6861           
=======================================
  Hits         6047     6047           
  Misses        814      814           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TalBarYakar TalBarYakar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a breaking change (although it actually fix a bug)
just notify product on the new approach

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.

[Bug]: JSON.ARRPOP treats a non-integer index as -1 and removes the last array element

2 participants