From c7a5859eada42724fa7088a4dea6e291869374f9 Mon Sep 17 00:00:00 2001 From: Ollie Shotton Date: Mon, 23 Oct 2023 17:18:02 +0100 Subject: [PATCH 1/2] Prove JsonPointer::remove() doesn't handle sequential arrays correctly Bug: T349483 --- tests/src/JsonPointerTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/src/JsonPointerTest.php b/tests/src/JsonPointerTest.php index bf025c3..2770cd3 100644 --- a/tests/src/JsonPointerTest.php +++ b/tests/src/JsonPointerTest.php @@ -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 From 22c33af4159bcc40f8ba2f023943fecac840c04d Mon Sep 17 00:00:00 2001 From: Ollie Shotton Date: Mon, 23 Oct 2023 17:18:57 +0100 Subject: [PATCH 2/2] Fix `JsonPointer::remove()` not handling sequential arrays correctly Bug: T349483 --- src/JsonPointer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/JsonPointer.php b/src/JsonPointer.php index 0b950a4..1311ad3 100644 --- a/src/JsonPointer.php +++ b/src/JsonPointer.php @@ -289,6 +289,7 @@ public static function remove(&$holder, $pathItems, $flags = 0) $isAssociative = true; break; } + $i++; } }