Commit cd71e5cc authored by webchick's avatar webchick

Issue #1645156 by attiks, tstoeckler, Albert Volkman, Carsten Müller,...

Issue #1645156 by attiks, tstoeckler, Albert Volkman, Carsten Müller, Sweetchuck: Fixed URL generation only works on port 80.
parent 90a48a9f
......@@ -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)) {
......
......@@ -107,6 +107,10 @@ function testDomainNameNegotiationPort() {
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 @@ function testDomainNameNegotiationPort() {
// 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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment