Skip to content

Commit 231a703

Browse files
authored
[6.x] Fixes Query Builder to only cast integer when given other than null (#39644)
* Add failing tests Signed-off-by: Mior Muhammad Zaki <[email protected]> * Only cast integer when given other than null Signed-off-by: Mior Muhammad Zaki <[email protected]> * Improve tests Signed-off-by: Mior Muhammad Zaki <[email protected]>
1 parent 4032dff commit 231a703

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/Illuminate/Database/Query/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1959,7 +1959,7 @@ public function limit($value)
19591959
$property = $this->unions ? 'unionLimit' : 'limit';
19601960

19611961
if ($value >= 0) {
1962-
$this->$property = (int) $value;
1962+
$this->$property = ! is_null($value) ? (int) $value : null;
19631963
}
19641964

19651965
return $this;

tests/Database/DatabaseQueryBuilderTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,14 @@ public function testLimitsAndOffsets()
12491249
$builder->select('*')->from('users')->offset(5)->limit(10);
12501250
$this->assertSame('select * from "users" limit 10 offset 5', $builder->toSql());
12511251

1252+
$builder = $this->getBuilder();
1253+
$builder->select('*')->from('users')->limit(null);
1254+
$this->assertSame('select * from "users"', $builder->toSql());
1255+
1256+
$builder = $this->getBuilder();
1257+
$builder->select('*')->from('users')->limit(0);
1258+
$this->assertSame('select * from "users" limit 0', $builder->toSql());
1259+
12521260
$builder = $this->getBuilder();
12531261
$builder->select('*')->from('users')->skip(5)->take(10);
12541262
$this->assertSame('select * from "users" limit 10 offset 5', $builder->toSql());
@@ -1260,6 +1268,14 @@ public function testLimitsAndOffsets()
12601268
$builder = $this->getBuilder();
12611269
$builder->select('*')->from('users')->skip(-5)->take(-10);
12621270
$this->assertSame('select * from "users" offset 0', $builder->toSql());
1271+
1272+
$builder = $this->getBuilder();
1273+
$builder->select('*')->from('users')->skip(null)->take(null);
1274+
$this->assertSame('select * from "users" offset 0', $builder->toSql());
1275+
1276+
$builder = $this->getBuilder();
1277+
$builder->select('*')->from('users')->skip(5)->take(null);
1278+
$this->assertSame('select * from "users" offset 5', $builder->toSql());
12631279
}
12641280

12651281
public function testForPage()

0 commit comments

Comments
 (0)