diff --git a/app/Services/Session/Handler.php b/app/Services/Session/Handler.php index db14151af..807955a6d 100644 --- a/app/Services/Session/Handler.php +++ b/app/Services/Session/Handler.php @@ -83,7 +83,10 @@ protected function getDefaultPayload($payload) $payload['path'] = $path === '/' ? $path : ('/' . $path); } if (\in_array($request->path(), ['ping', 'User/Settings/Ajax'])) { - $payload['path'] = \parse_url($request->header('Referer'), \PHP_URL_PATH); + $parseUrl = \parse_url($request->header('Referer'), \PHP_URL_PATH); + if ($parseUrl) { + $payload['path'] = $parseUrl; + } } } diff --git a/tests/Unit/OnlineUsers/PingTest.php b/tests/Unit/OnlineUsers/PingTest.php index d028aff9c..0898940af 100644 --- a/tests/Unit/OnlineUsers/PingTest.php +++ b/tests/Unit/OnlineUsers/PingTest.php @@ -33,6 +33,27 @@ public function ajaxSettingsIsSavedAsReferer(): void $this->assertSame('/Mikroblogi', $this->sessionPath()); } + #[Test] + public function ignoreEmptyHttpRefererPathEmpty(): void + { + $this->request('/ping', 'http://localhost:8880/'); + $this->assertSame('/', $this->sessionPath()); + } + + #[Test] + public function ignoreEmptyHttpRefererPathMissing(): void + { + $this->request('/ping', 'http://localhost:8880'); + $this->assertSame('/ping', $this->sessionPath()); + } + + #[Test] + public function ignoreEmptyHttpRefererMissing(): void + { + $this->request('/ping', ''); + $this->assertSame('/ping', $this->sessionPath()); + } + private function sessionPath(): string { /** @var Handler $handler */