From 6895cc3c200b6c0df81f32b0bf116c01cc834c62 Mon Sep 17 00:00:00 2001 From: webchick <webchick@24967.no-reply.drupal.org> Date: Sat, 30 Jun 2012 11:36:17 -0700 Subject: [PATCH] Issue #1645156 by attiks: Fixed URL generation only works on port 80. --- .../modules/language/language.negotiation.inc | 9 ++++++ .../Tests/LanguageUrlRewritingTest.php | 30 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/core/modules/language/language.negotiation.inc b/core/modules/language/language.negotiation.inc index d5734131d67f..01c39a8dd976 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 137bba971645..1772129d9c96 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.'); + } + } -- GitLab