Skip to content

Commit 01eedf4

Browse files
authored
fix data_has empty check (#57586)
1 parent 24f0f28 commit 01eedf4

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Illuminate/Collections/helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function data_fill(&$target, $key, $value)
4444
*/
4545
function data_has($target, $key): bool
4646
{
47-
if (empty($key)) {
47+
if (is_null($key) || $key === []) {
4848
return false;
4949
}
5050

tests/Support/SupportHelpersTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ public function testDataHas()
225225
$dottedArray = ['users' => ['first.name' => 'Taylor', 'middle.name' => null]];
226226
$arrayAccess = new SupportTestArrayAccess(['price' => 56, 'user' => new SupportTestArrayAccess(['name' => 'John']), 'email' => null]);
227227
$sameKeyMultiLevel = (object) ['name' => 'Taylor', 'company' => ['name' => 'Laravel']];
228+
$plainArray = [1, 2, 3];
228229

229230
$this->assertTrue(data_has($object, 'users.name.0'));
230231
$this->assertTrue(data_has($array, '0.users.0.name'));
@@ -244,6 +245,13 @@ public function testDataHas()
244245
$this->assertTrue(data_has($sameKeyMultiLevel, 'name'));
245246
$this->assertTrue(data_has($sameKeyMultiLevel, 'company.name'));
246247
$this->assertFalse(data_has($sameKeyMultiLevel, 'foo.name'));
248+
$this->assertTrue(data_has($plainArray, 0));
249+
$this->assertTrue(data_has($plainArray, '0'));
250+
$this->assertFalse(data_has($plainArray, 4));
251+
$this->assertFalse(data_has($plainArray, '4'));
252+
$this->assertFalse(data_has($plainArray, ''));
253+
$this->assertFalse(data_has($plainArray, []));
254+
$this->assertFalse(data_has($plainArray, null));
247255
}
248256

249257
public function testDataGet()

0 commit comments

Comments
 (0)