diff --git a/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php index 698057b..6e5b7a9 100644 --- a/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php @@ -81,10 +81,13 @@ public function onKernelRequestFrontPageResolve(GetResponseEvent $event) { * The Event to process. */ public function onKernelRequestLanguageResolve(GetResponseEvent $event) { - $request = $event->getRequest(); - $path = _language_resolved_path(); - if ($path !== NULL) { - $this->setPath($request, $path); + // We need to act only on the master request, otherwise subrequests will + // inherit the main request path and an infinite loop will be started. + if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) { + $path = _language_resolved_path(); + if ($path !== NULL) { + $this->setPath($event->getRequest(), $path); + } } } diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php index 7cfa8c1..3effed4 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php @@ -19,7 +19,7 @@ class LanguageUrlRewritingTest extends WebTestBase { * * @var array */ - public static $modules = array('language'); + public static $modules = array('language', 'language_test'); public static function getInfo() { return array( @@ -59,6 +59,10 @@ function testUrlRewritingEdgeCases() { $non_existing = language_default(); $non_existing->langcode = $this->randomName(); $this->checkUrl($non_existing, 'Path language is ignored if language is not installed.', 'URL language negotiation does not work with non-installed languages'); + + // Check that URL rewriting is not applied to subrequests. + $this->drupalGet('language_test/subrequest'); + $this->assertText($this->web_user->name, 'Page correctly retrieved'); } /** diff --git a/core/modules/language/tests/language_test.module b/core/modules/language/tests/language_test.module index c15cc80..4355852 100644 --- a/core/modules/language/tests/language_test.module +++ b/core/modules/language/tests/language_test.module @@ -5,6 +5,9 @@ * Mock module for language layer tests. */ +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\HttpKernelInterface; + /** * Implements hook_boot(). * @@ -106,3 +109,25 @@ function language_test_store_language_negotiation() { function language_test_language_negotiation_method($languages) { return 'it'; } + +/** + * Implements hook_menu(). + */ +function language_test_menu() { + $items = array(); + + $items['language_test/subrequest'] = array( + 'page callback' => 'language_test_subrequest', + 'access callback' => TRUE, + 'type' => MENU_CALLBACK, + ); + + return $items; +} + +/** + * Page callback. Uses a subrequest to retrieve the 'user' page. + */ +function language_test_subrequest() { + return drupal_container()->get('http_kernel')->handle(Request::create('/user'), HttpKernelInterface::SUB_REQUEST); +}