summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2012-08-30 22:39:23 (GMT)
committerwebchick2012-08-30 22:39:23 (GMT)
commitcd71e5ccde38061151b0822c0c7c5631f0687c62 (patch)
treedc78136e581c3117ac036165c6814987da9ad5b3
parent90a48a9fe678a0f801a1bb3d27fe1834d05e248f (diff)
Issue #1645156 by attiks, tstoeckler, Albert Volkman, Carsten Müller, Sweetchuck: Fixed URL generation only works on port 80.
-rw-r--r--core/modules/language/language.negotiation.inc25
-rw-r--r--core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php24
2 files changed, 41 insertions, 8 deletions
diff --git a/core/modules/language/language.negotiation.inc b/core/modules/language/language.negotiation.inc
index 48a80831..b78dff2d 100644
--- a/core/modules/language/language.negotiation.inc
+++ b/core/modules/language/language.negotiation.inc
@@ -392,18 +392,31 @@ function language_url_rewrite_url(&$path, &$options) {
case LANGUAGE_NEGOTIATION_URL_DOMAIN:
$domains = language_negotiation_url_domains();
if (is_object($options['language']) && !empty($domains[$options['language']->langcode])) {
- // Ask for an absolute URL with our modified base_url.
global $is_https;
+
+ // Save the original base URL. If it contains a port, we need to
+ // retain it below.
+ if (!empty($options['base_url'])) {
+ // The colon in the URL scheme messes up the port checking below.
+ $normalized_base_url = str_replace(array('https://', 'http://'), '', $options['base_url']);
+
+ }
+
+ // Ask for an absolute URL with our modified base URL.
$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.
+ // In case either the original base URL or the HTTP host contains a
+ // port, retain it.
$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($normalized_base_url) && strpos($normalized_base_url, ':') !== FALSE) {
+ list($host, $port) = explode(':', $normalized_base_url);
+ $options['base_url'] .= ':' . $port;
+ }
+ elseif (strpos($http_host, ':') !== FALSE) {
+ list($host, $port) = explode(':', $http_host);
+ $options['base_url'] .= ':' . $port;
}
if (isset($options['https']) && variable_get('https', FALSE)) {
diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php
index 72f2116..9e28df6 100644
--- a/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php
+++ b/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php
@@ -107,6 +107,10 @@ class LanguageUrlRewritingTest extends WebTestBase {
drupal_static_reset('language_url_outbound_alter');
drupal_static_reset('language_url_rewrite_url');
+ // In case index.php is part of the URLs, we need to adapt the asserted
+ // URLs as well.
+ $index_php = strpos(url('', array('absolute' => TRUE)), 'index.php') !== FALSE;
+
// Remember current HTTP_HOST.
$http_host = $_SERVER['HTTP_HOST'];
// Fake a different port.
@@ -114,9 +118,25 @@ class LanguageUrlRewritingTest extends WebTestBase {
// Create an absolute French link.
$language = language_load('fr');
- $url = url('', array('absolute' => TRUE, 'language' => $language));
+ $url = url('', array(
+ 'absolute' => TRUE,
+ 'language' => $language,
+ ));
+
+ $expected = $index_php ? 'http://example.fr:88/index.php/' : 'http://example.fr:88/';
+
+ $this->assertEqual($url, $expected, 'The right port is used.');
+
+ // If we set the port explicitly in url(), it should not be overriden.
+ $url = url('', array(
+ 'absolute' => TRUE,
+ 'language' => $language,
+ 'base_url' => $GLOBALS['base_url'] . ':90',
+ ));
+
+ $expected = $index_php ? 'http://example.fr:90/index.php/' : 'http://example.fr:90/';
- $this->assertTrue(strcmp($url, 'http://example.fr:88/') == 0, 'The right port is used.');
+ $this->assertEqual($url, $expected, 'A given port is not overriden.');
// Restore HTTP_HOST.
$_SERVER['HTTP_HOST'] = $http_host;