diff --git a/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php index 698057bf44ae3aab1be54bb7f702c44962ea94be..6e5b7a967c159e04795c48ed5050e5de928b521b 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 7cfa8c159300414f39730399daaa26ba231c48db..3effed4fb80463194b40355e315c07a5e465213d 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/language_test.module b/core/modules/language/tests/language_test/language_test.module index e83f34c5d0423f418d34c1684ced928555904534..cb97937ebb2bbcfed99a8f15f2a0170c051c51a3 100644 --- a/core/modules/language/tests/language_test/language_test.module +++ b/core/modules/language/tests/language_test/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_init(). */ @@ -94,3 +97,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); +}