Skip to content

Commit

Permalink
Merge pull request #67 from wmde/fix-remove-operation
Browse files Browse the repository at this point in the history
Fix `JsonPointer::remove()` not handling sequential arrays correctly
  • Loading branch information
vearutop authored Nov 17, 2023
2 parents f4e5117 + 22c33af commit 17bfc66
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/JsonPointer.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ public static function remove(&$holder, $pathItems, $flags = 0)
$isAssociative = true;
break;
}
$i++;
}
}

Expand Down
7 changes: 7 additions & 0 deletions tests/src/JsonPointerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ public function testGetSetDeleteObject()
$this->assertEquals(null, $s->one->two);
}

public function testSequentialArrayIsPreserved()
{
$json = [ 'l1' => [ 0 => 'foo', 1 => 'bar', 2 => 'baz' ] ];
JsonPointer::remove($json, ['l1', '1'], JsonPointer::TOLERATE_ASSOCIATIVE_ARRAYS);
$this->assertSame('{"l1":["foo","baz"]}', json_encode($json));
}

}

class Sample
Expand Down

0 comments on commit 17bfc66

Please sign in to comment.