Skip to content

Compatibility with unserialized cookies #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: release/0.10
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Events/Listeners/CatchSluggableRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Session\SessionManager;
use Illuminate\Routing\Events\RouteMatched;
use Illuminate\Contracts\Encryption\Encrypter;
use Illuminate\Cookie\Middleware\EncryptCookies;

class CatchSluggableRoutes
{
Expand Down Expand Up @@ -69,9 +70,10 @@ protected function startSession(Request $request)
public function getSession(Request $request)
{
return tap($this->sessionManager->driver(), function ($session) use ($request) {
if ($encryptedSessionId = $request->cookies->get($session->getName())) {
$sessionId = $this->encrypter->decrypt($encryptedSessionId);
$isSerialized = EncryptCookies::serialized($session->getName());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryzr can you verify that tabs or spaces would be better here please?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screen Shot 2022-12-12 at 10 10 03 am

I recommend something like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably also add a test

<?php

namespace Tests;

use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\TestCase;

class FizzBuzzTest extends TestCase
{
    use CreatesApplication, DatabaseMigrations;

    public function testItPerformsFizzBuzzCorrectly()
    {
        $this->runDatabaseMigrations();
        $this->seed();

        $this->assertEquals("12Fizz4BuzzFizz78FizzBuzz11Fizz1314FizzBuzz1617Fizz19BuzzFizz2223FizzBuzz26Fizz2829FizzBuzz3132Fizz34BuzzFizz3738FizzBuzz41Fizz4344FizzBuzz4647Fizz49BuzzFizz5253FizzBuzz56Fizz5859FizzBuzz6162Fizz64BuzzFizz6768FizzBuzz71Fizz7374FizzBuzz7677Fizz79BuzzFizz8283FizzBuzz86Fizz8889FizzBuzz9192Fizz94BuzzFizz9798FizzBuzz", logFizzBuzz(), 'Bad Fizz Buzz');
    }
}


if ($encryptedSessionId = $request->cookies->get($session->getName())) {
$sessionId = $this->encrypter->decrypt($encryptedSessionId, $isSerialized);
$session->setId($sessionId);
}
});
Expand Down