Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

merged branch uwej711/fix_locale_is_overridden (PR #7516)

This PR was merged into the 2.2 branch.

Discussion
----------

[HttpKernel] fix overwriting of request's locale by LocaleListener if attribute _locale is missing

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #7474
| License       | MIT
| Doc PR        | n.a.

Commits
-------

e8cae94 fix overwriting of request's locale if attribute _locale is missing
  • Loading branch information...
commit 689653f51dd92bcd88522592077f53fea0534eef 2 parents 7379b9e + e8cae94
@fabpot fabpot authored
View
2  src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php
@@ -50,7 +50,7 @@ public function onKernelRequest(GetResponseEvent $event)
$request = $event->getRequest();
$request->setDefaultLocale($this->defaultLocale);
- $this->setLocale($request, $request->attributes->get('_locale', $this->defaultLocale));
+ $this->setLocale($request, $request->attributes->get('_locale', $request->getLocale()));
array_unshift($this->locales, $request->getLocale());
}
View
11 src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleListenerTest.php
@@ -68,6 +68,17 @@ public function testLocaleSetForRoutingContext()
$listener->onKernelRequest($this->getEvent($request));
}
+ public function testRequestLocaleIsNotOverridden()
+ {
+ $request = Request::create('/');
+ $request->setLocale('de');
+ $listener = new LocaleListener('fr');
+ $event = $this->getEvent($request);
+
+ $listener->onKernelRequest($event);
+ $this->assertEquals('de', $request->getLocale());
+ }
+
private function getEvent(Request $request)
{
return new GetResponseEvent($this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'), $request, HttpKernelInterface::MASTER_REQUEST);
Please sign in to comment.
Something went wrong with that request. Please try again.