diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index 00131c80054f..fe603c18fade 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -193,6 +193,10 @@ public function whereKey($id) return $this; } + if ($id !== null && $this->model->getKeyType() === 'string') { + $id = (string) $id; + } + return $this->where($this->model->getQualifiedKeyName(), '=', $id); } @@ -210,6 +214,10 @@ public function whereKeyNot($id) return $this; } + if ($id !== null && $this->model->getKeyType() === 'string') { + $id = (string) $id; + } + return $this->where($this->model->getQualifiedKeyName(), '!=', $id); } diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index e925fedd2366..78c4b5c0af53 100755 --- a/src/Illuminate/Foundation/Application.php +++ b/src/Illuminate/Foundation/Application.php @@ -31,7 +31,7 @@ class Application extends Container implements ApplicationContract, HttpKernelIn * * @var string */ - const VERSION = '6.18.36'; + const VERSION = '6.18.37'; /** * The base path for the Laravel installation. diff --git a/src/Illuminate/Redis/Connectors/PhpRedisConnector.php b/src/Illuminate/Redis/Connectors/PhpRedisConnector.php index 5942d7121cb1..b01f114205d8 100644 --- a/src/Illuminate/Redis/Connectors/PhpRedisConnector.php +++ b/src/Illuminate/Redis/Connectors/PhpRedisConnector.php @@ -7,6 +7,7 @@ use Illuminate\Redis\Connections\PhpRedisConnection; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Redis as RedisFacade; +use Illuminate\Support\Str; use LogicException; use Redis; use RedisCluster; @@ -175,7 +176,7 @@ protected function createRedisClusterInstance(array $servers, array $options) protected function formatHost(array $options) { if (isset($options['scheme'])) { - return "{$options['scheme']}://{$options['host']}"; + return Str::start($options['host'], "{$options['scheme']}://"); } return $options['host']; diff --git a/src/Illuminate/Session/Middleware/AuthenticateSession.php b/src/Illuminate/Session/Middleware/AuthenticateSession.php index 85a9b39d84ad..5da389ae3d39 100644 --- a/src/Illuminate/Session/Middleware/AuthenticateSession.php +++ b/src/Illuminate/Session/Middleware/AuthenticateSession.php @@ -40,9 +40,9 @@ public function handle($request, Closure $next) } if ($this->auth->viaRemember()) { - $passwordHash = explode('|', $request->cookies->get($this->auth->getRecallerName()))[2]; + $passwordHash = explode('|', $request->cookies->get($this->auth->getRecallerName()))[2] ?? null; - if ($passwordHash != $request->user()->getAuthPassword()) { + if (! $passwordHash || $passwordHash != $request->user()->getAuthPassword()) { $this->logout($request); } } diff --git a/tests/Database/DatabaseEloquentBuilderTest.php b/tests/Database/DatabaseEloquentBuilderTest.php index 8276ea03e96b..0b4530802a9d 100755 --- a/tests/Database/DatabaseEloquentBuilderTest.php +++ b/tests/Database/DatabaseEloquentBuilderTest.php @@ -31,7 +31,9 @@ protected function tearDown(): void public function testFindMethod() { $builder = m::mock(Builder::class.'[first]', [$this->getMockQueryBuilder()]); - $builder->setModel($this->getMockModel()); + $model = $this->getMockModel(); + $builder->setModel($model); + $model->shouldReceive('getKeyType')->once()->andReturn('int'); $builder->getQuery()->shouldReceive('where')->once()->with('foo_table.foo', '=', 'bar'); $builder->shouldReceive('first')->with(['column'])->andReturn('baz'); @@ -76,6 +78,7 @@ public function testFindManyMethod() public function testFindOrNewMethodModelFound() { $model = $this->getMockModel(); + $model->shouldReceive('getKeyType')->once()->andReturn('int'); $model->shouldReceive('findOrNew')->once()->andReturn('baz'); $builder = m::mock(Builder::class.'[first]', [$this->getMockQueryBuilder()]); @@ -91,6 +94,7 @@ public function testFindOrNewMethodModelFound() public function testFindOrNewMethodModelNotFound() { $model = $this->getMockModel(); + $model->shouldReceive('getKeyType')->once()->andReturn('int'); $model->shouldReceive('findOrNew')->once()->andReturn(m::mock(Model::class)); $builder = m::mock(Builder::class.'[first]', [$this->getMockQueryBuilder()]); @@ -109,7 +113,9 @@ public function testFindOrFailMethodThrowsModelNotFoundException() $this->expectException(ModelNotFoundException::class); $builder = m::mock(Builder::class.'[first]', [$this->getMockQueryBuilder()]); - $builder->setModel($this->getMockModel()); + $model = $this->getMockModel(); + $model->shouldReceive('getKeyType')->once()->andReturn('int'); + $builder->setModel($model); $builder->getQuery()->shouldReceive('where')->once()->with('foo_table.foo', '=', 'bar'); $builder->shouldReceive('first')->with(['column'])->andReturn(null); $builder->findOrFail('bar', ['column']); @@ -1017,11 +1023,39 @@ public function testWhereKeyMethodWithInt() $int = 1; + $model->shouldReceive('getKeyType')->once()->andReturn('int'); $builder->getQuery()->shouldReceive('where')->once()->with($keyName, '=', $int); $builder->whereKey($int); } + public function testWhereKeyMethodWithStringZero() + { + $model = new EloquentBuilderTestStubStringPrimaryKey(); + $builder = $this->getBuilder()->setModel($model); + $keyName = $model->getQualifiedKeyName(); + + $int = 0; + + $builder->getQuery()->shouldReceive('where')->once()->with($keyName, '=', (string) $int); + + $builder->whereKey($int); + } + + /** @group Foo */ + public function testWhereKeyMethodWithStringNull() + { + $model = new EloquentBuilderTestStubStringPrimaryKey(); + $builder = $this->getBuilder()->setModel($model); + $keyName = $model->getQualifiedKeyName(); + + $builder->getQuery()->shouldReceive('where')->once()->with($keyName, '=', m::on(function ($argument) { + return $argument === null; + })); + + $builder->whereKey(null); + } + public function testWhereKeyMethodWithArray() { $model = $this->getMockModel(); @@ -1048,6 +1082,33 @@ public function testWhereKeyMethodWithCollection() $builder->whereKey($collection); } + public function testWhereKeyNotMethodWithStringZero() + { + $model = new EloquentBuilderTestStubStringPrimaryKey(); + $builder = $this->getBuilder()->setModel($model); + $keyName = $model->getQualifiedKeyName(); + + $int = 0; + + $builder->getQuery()->shouldReceive('where')->once()->with($keyName, '!=', (string) $int); + + $builder->whereKeyNot($int); + } + + /** @group Foo */ + public function testWhereKeyNotMethodWithStringNull() + { + $model = new EloquentBuilderTestStubStringPrimaryKey(); + $builder = $this->getBuilder()->setModel($model); + $keyName = $model->getQualifiedKeyName(); + + $builder->getQuery()->shouldReceive('where')->once()->with($keyName, '!=', m::on(function ($argument) { + return $argument === null; + })); + + $builder->whereKeyNot(null); + } + public function testWhereKeyNotMethodWithInt() { $model = $this->getMockModel(); @@ -1056,6 +1117,7 @@ public function testWhereKeyNotMethodWithInt() $int = 1; + $model->shouldReceive('getKeyType')->once()->andReturn('int'); $builder->getQuery()->shouldReceive('where')->once()->with($keyName, '!=', $int); $builder->whereKeyNot($int); @@ -1414,3 +1476,12 @@ class EloquentBuilderTestStubWithoutTimestamp extends Model protected $table = 'table'; } + +class EloquentBuilderTestStubStringPrimaryKey extends Model +{ + public $incrementing = false; + + protected $table = 'foo_table'; + + protected $keyType = 'string'; +}