diff --git a/core/includes/locale.inc b/core/includes/locale.inc index e2a79b6..690208a 100644 --- a/core/includes/locale.inc +++ b/core/includes/locale.inc @@ -438,8 +438,18 @@ function locale_language_url_rewrite_url(&$path, &$options) { $domains = locale_language_negotiation_url_domains(); if (!empty($domains[$options['language']->langcode])) { // Ask for an absolute URL with our modified base_url. + global $is_https; + $url_scheme = ($is_https) ? 'https://' : 'http://'; $options['absolute'] = TRUE; - $options['base_url'] = $domains[$options['language']->langcode]; + $options['base_url'] = $url_scheme . $domains[$options['language']->langcode]; + if (isset($options['https']) && variable_get('https', FALSE)) { + if ($options['https'] === TRUE) { + $options['base_url'] = str_replace('http://', 'https://', $options['base_url']); + } + elseif ($options['https'] === FALSE) { + $options['base_url'] = str_replace('https://', 'http://', $options['base_url']); + } + } } break; diff --git a/core/modules/locale/locale.test b/core/modules/locale/locale.test index f102d4b..d222c8f 100644 --- a/core/modules/locale/locale.test +++ b/core/modules/locale/locale.test @@ -2212,6 +2212,59 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase { $fields = $this->xpath('//div[@id="site-name"]//a[@rel="home" and @href=:url]//span', $args); $this->assertTrue($fields[0] == 'Drupal', t('URLs are rewritten using the browser language.')); } + + /** + * Test if the url function returns the right url when using different domains for different languages. + */ + function testLanguageDomain() { + // Add the Italian language. + $langcode_browser_fallback = 'it'; + $language = (object) array( + 'langcode' => $langcode_browser_fallback, + ); + language_save($language); + $languages = language_list(); + + // Enable browser and URL language detection. + $edit = array( + 'language[enabled][locale-browser]' => TRUE, + 'language[enabled][locale-url]' => TRUE, + 'language[weight][locale-browser]' => -8, + 'language[weight][locale-url]' => -10, + ); + $this->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings')); + + // Change the domain for the Italian language. + $edit = array( + 'locale_language_negotiation_url_part' => 1, + 'domain[it]' => 'it.example.com', + ); + $this->drupalPost('admin/config/regional/language/configure/url', $edit, t('Save configuration')); + + global $is_https; + // Test URL in another language: http://it.example.com/?q=admin + // Base path gives problems on the testbot, so $correct_link is hard-coded + // @see UrlAlterFunctionalTest::assertUrlOutboundAlter (path.test) + $italian_url = url('admin', array('language' => $languages['it'])); + $url_scheme = ($is_https) ? 'https://' : 'http://'; + $correct_link = $url_scheme . 'it.example.com/?q=admin'; + $this->assertTrue($italian_url == $correct_link, t('The url() function returns the right url (@url) in accordance with the chosen language', array('@url' => $italian_url))); + + // Test https via options + variable_set('https', TRUE); + $italian_url = url('admin', array('https' => TRUE, 'language' => $languages['it'])); + $correct_link = 'https://it.example.com/?q=admin'; + $this->assertTrue($italian_url == $correct_link, t('The url() function returns the right https url (via options) (@url) in accordance with the chosen language', array('@url' => $italian_url))); + variable_set('https', FALSE); + + //Test https via current url scheme + $temp_https = $is_https; + $is_https = TRUE; + $italian_url = url('admin', array('language' => $languages['it'])); + $correct_link = 'https://it.example.com/?q=admin'; + $this->assertTrue($italian_url == $correct_link, t('The url() function returns the right url (via current url scheme) (@url) in accordance with the chosen language', array('@url' => $italian_url))); + $is_https = $temp_https; + } } /**