diff --git a/system/HTTP/RequestTrait.php b/system/HTTP/RequestTrait.php index 43a4f23a0e87..a47d4c7a6980 100644 --- a/system/HTTP/RequestTrait.php +++ b/system/HTTP/RequestTrait.php @@ -290,7 +290,7 @@ public function fetchGlobal(string $name, $index = null, ?int $filter = null, $f } // Does the index contain array notation? - if (($count = preg_match_all('/(?:^[^\[]+)|\[[^]]*\]/', $index, $matches)) > 1) { + if (is_string($index) && ($count = preg_match_all('/(?:^[^\[]+)|\[[^]]*\]/', $index, $matches)) > 1) { $value = $this->globals[$name]; for ($i = 0; $i < $count; $i++) { diff --git a/tests/system/Test/FeatureTestTraitTest.php b/tests/system/Test/FeatureTestTraitTest.php index be3d590bd15a..cd1c845342f1 100644 --- a/tests/system/Test/FeatureTestTraitTest.php +++ b/tests/system/Test/FeatureTestTraitTest.php @@ -557,7 +557,7 @@ public function testCallPutWithJsonRequestAndREQUEST(): void $this->assertStringContainsString('[]', $response->getBody()); } - public function testCallWithJsonRequest(): void + public function testCallWithAssociativeJsonRequest(): void { $this->withRoutes([ [ @@ -581,6 +581,26 @@ public function testCallWithJsonRequest(): void $response->assertJSONExact($data); } + public function testCallWithListJsonRequest(): void + { + $this->withRoutes([ + [ + 'POST', + 'home', + '\Tests\Support\Controllers\Popcorn::echoJson', + ], + ]); + $data = [ + ['one' => 1, 'two' => 2], + ['one' => 2, 'two' => 2], + ]; + $response = $this->withBodyFormat('json') + ->call(Method::POST, 'home', $data); + + $response->assertOK(); + $response->assertJSONExact($data); + } + public function testSetupRequestBodyWithParams(): void { $request = $this->setupRequest('post', 'home');