Skip to content
Snippets Groups Projects
Commit 6895cc3c authored by Angie Byron's avatar Angie Byron
Browse files

Issue #1645156 by attiks: Fixed URL generation only works on port 80.

parent 4cc4103e
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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']);
......
......@@ -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.');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment