Skip to content

Commit 3ffa468

Browse files
committed
Reject float as column name
1 parent 205db4e commit 3ffa468

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/Query/Builder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,10 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
971971
throw new ArgumentCountError(sprintf('Too few arguments to function %s(%s), 1 passed and at least 2 expected when the 1st is not an array or a callable', __METHOD__, var_export($column, true)));
972972
}
973973

974+
if (! is_int($column) && ! is_string($column)) {
975+
throw new InvalidArgumentException(sprintf('First argument of %s must be a column name as "string". Got "%s"', __METHOD__, get_debug_type($column)));
976+
}
977+
974978
return parent::where(...$params);
975979
}
976980

tests/ModelTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -986,9 +986,5 @@ public function testNumericFieldName(): void
986986
$found = User::where('2.3', 'two.three')->first();
987987
$this->assertInstanceOf(User::class, $found);
988988
$this->assertEquals([3 => 'two.three'], $found[2]);
989-
990-
$found = User::where(2.3, 'two.three')->first();
991-
$this->assertInstanceOf(User::class, $found);
992-
$this->assertEquals([3 => 'two.three'], $found[2]);
993989
}
994990
}

tests/Query/BuilderTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,12 @@ public static function provideExceptions(): iterable
12191219
'Invalid time format, expected HH:MM:SS, HH:MM or HH, got "stdClass"',
12201220
fn (Builder $builder) => $builder->whereTime('created_at', new stdClass()),
12211221
];
1222+
1223+
yield 'where invalid column type' => [
1224+
InvalidArgumentException::class,
1225+
'First argument of MongoDB\Laravel\Query\Builder::where must be a column name as "string". Got "float"',
1226+
fn (Builder $builder) => $builder->where(2.3, '>', 1),
1227+
];
12221228
}
12231229

12241230
/** @dataProvider getEloquentMethodsNotSupported */

0 commit comments

Comments
 (0)