Skip to content
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

Invalid locale cookie is set in the redirect response of LocaleCookieRedirect #714

Open
okovpashko opened this issue Mar 28, 2020 · 0 comments · May be fixed by #715
Open

Invalid locale cookie is set in the redirect response of LocaleCookieRedirect #714

okovpashko opened this issue Mar 28, 2020 · 0 comments · May be fixed by #715

Comments

@okovpashko
Copy link

Describe the bug
Hello. I found a potential bug when was writing integration tests for the site that uses this plugin.

To Reproduce
Steps to reproduce the behavior:

  1. Open a localized URL
  2. Ensure that locale cookie is set
  3. Open an URL for the default language
  4. Check Set-Cookie response header. It will be locale=deleted for the homepage or will contain the page slug for the other pages.

or

  1. Use CURL to send a request to the URL for the default language with the locale cookie for the another language:
curl -b 'locale=fr' -I http://example.com
  1. Check SetCookie response header:
Set-Cookie: locale=deleted; expires=Fri, 29-Mar-2019 18:03:28 GMT; Max-Age=0; path=/; httponly

Expected behavior
locale cookie must be preserved

More info:

  • Version of Laravel: 5.5
  • Version of the Laravel-localization package: 1.5
  • Which middleware is used in Route::groups: LocaleCookieRedirect, LaravelLocalizationRedirectFilter
  • Copy of the config file:
<?php

return [
    'supportedLocales' => [
        'de'          => ['name' => 'German',                 'script' => 'Latn', 'native' => 'Deutsch', 'regional' => 'de_DE', 'comprehensible' => ['de-de', 'de']],
        'en'          => ['name' => 'English',                'script' => 'Latn', 'native' => 'English', 'regional' => 'en_US', 'comprehensible' => ['en-gb', 'en-us', 'en']],
        'fr'          => ['name' => 'French',                 'script' => 'Latn', 'native' => 'Français', 'regional' => 'fr_FR', 'comprehensible' => ['fr-fr', 'fr']],
        'pt-br'       => ['name' => 'Brazilian Portuguese',   'script' => 'Latn', 'native' => 'Português do Brasil', 'regional' => 'pt_BR', 'comprehensible' => ['pt-BR', 'pt']],
        'es'          => ['name' => 'Spanish',                'script' => 'Latn', 'native' => 'Español', 'regional' => 'es_ES', 'comprehensible' => ['es_ES','es']],
        'it'          => ['name' => 'Italian',                'script' => 'Latn', 'native' => 'Italiano', 'regional' => 'it_IT', 'comprehensible' => ['it', 'it_IT']],
        'ru'          => ['name' => 'Russian',                'script' => 'Cyrl', 'native' => 'Pусский', 'regional' => 'ru_RU', 'comprehensible' => ['ru_RU', 'ru']],
    ],
    'useAcceptLanguageHeader' => true,
    'hideDefaultLocaleInURL' => true,
];

Additional context
This issue does not break the site behavior because after the redirect we got a locale in the URL and LocaleCookieRedirect middleware is set the correct locale to the cookies again.

Probably the issue is caused by this line. We should use no params[0], but $locale variable as the cookie value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant