laravel-localization
laravel-localization copied to clipboard
Invalid locale cookie is set in the redirect response of `LocaleCookieRedirect`
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:
- Open a localized URL
- Ensure that
locale
cookie is set - Open an URL for the default language
- Check
Set-Cookie
response header. It will belocale=deleted
for the homepage or will contain the page slug for the other pages.
or
- 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
- 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.