diff --git a/core/modules/language/language.negotiation.inc b/core/modules/language/language.negotiation.inc index d5734131d67fd6960036ebeffbf655dbb12622c5..01c39a8dd9761996315e589536d273aab525d786 100644 --- a/core/modules/language/language.negotiation.inc +++ b/core/modules/language/language.negotiation.inc @@ -383,6 +383,15 @@ function language_url_rewrite_url(&$path, &$options) { $url_scheme = ($is_https) ? 'https://' : 'http://'; $options['absolute'] = TRUE; $options['base_url'] = $url_scheme . $domains[$options['language']->langcode]; + + // HTTP_HOST will optionally contain the port. Preserve that for + // the domain of the target language as well. + $http_host = $_SERVER['HTTP_HOST']; + if (strpos($http_host, ':') !== FALSE) { + $http_host_tmp = explode(':', $http_host); + $options['base_url'] .= ':' . end($http_host_tmp); + } + if (isset($options['https']) && variable_get('https', FALSE)) { if ($options['https'] === TRUE) { $options['base_url'] = str_replace('http://', 'https://', $options['base_url']); diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php index 137bba971645a1bbbb5b673c26a201e512370c83..1772129d9c96115beb2f12a7a3b7ed8cd94f4f0f 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php @@ -79,4 +79,34 @@ private function checkUrl($language, $message1, $message2) { $this->drupalGet("$prefix/$path"); $this->assertResponse(404, $message2); } + + /** + * Check URL rewriting when using a domain name and a non-standard port. + */ + function testDomainNameNegotiationPort() { + $language_domain = 'example.fr'; + $edit = array( + 'language_negotiation_url_part' => 1, + 'domain[fr]' => $language_domain + ); + $this->drupalPost('admin/config/regional/language/detection/url', $edit, t('Save configuration')); + + // Enable domain configuration. + variable_set('language_negotiation_url_part', LANGUAGE_NEGOTIATION_URL_DOMAIN); + + // Reset static caching. + drupal_static_reset('language_list'); + drupal_static_reset('language_url_outbound_alter'); + drupal_static_reset('language_url_rewrite_url'); + + // Fake a different port. + $_SERVER['HTTP_HOST'] .= ':88'; + + // Create an absolute French link. + $language = language_load('fr'); + $url = url('', array('absolute' => TRUE, 'language' => $language)); + + $this->assertTrue(strcmp($url, 'http://example.fr:88/') == 0, 'The right port is used.'); + } + }