diff --git a/core/modules/language/language.admin.inc b/core/modules/language/language.admin.inc index e17988d..ca1d288 100644 --- a/core/modules/language/language.admin.inc +++ b/core/modules/language/language.admin.inc @@ -746,6 +746,11 @@ function language_negotiation_configure_url_form_validate($form, &$form_state) { form_error($form['prefix'][$langcode], t('The prefix may only be left blank for the default language.')); } } + elseif (strpos($value, '/') !== FALSE) { + // Throw a form error if the strings contains a slash, + // which would not work. + form_error($form['prefix'][$langcode], t('The prefix may not contain a slash.')); + } elseif (isset($count[$value]) && $count[$value] > 1) { // Throw a form error if there are two languages with the same // domain/prefix. diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php index 0372e1b..76af730 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php @@ -41,40 +41,62 @@ class LanguageConfigurationTest extends WebTestBase { // Check if the Default English language has no path prefix. $this->drupalGet('admin/config/regional/language/detection/url'); - $this->assertFieldByXPath('//input[@name="prefix[en]"]', '', t('Default English has no path prefix.')); + $this->assertFieldByXPath('//input[@name="prefix[en]"]', '', 'Default English has no path prefix.'); // Add predefined language. $edit = array( 'predefined_langcode' => 'fr', ); - $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); + $this->drupalPost('admin/config/regional/language/add', $edit, 'Add language'); $this->assertText('French'); - $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), t('Correct page redirection.')); + $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.'); // Check if the Default English language has no path prefix. $this->drupalGet('admin/config/regional/language/detection/url'); - $this->assertFieldByXPath('//input[@name="prefix[en]"]', '', t('Default English has no path prefix.')); + $this->assertFieldByXPath('//input[@name="prefix[en]"]', '', 'Default English has no path prefix.'); // Check if French has a path prefix. $this->drupalGet('admin/config/regional/language/detection/url'); - $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'fr', t('French has a path prefix.')); + $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'fr', 'French has a path prefix.'); // Check if we can change the default language. $this->drupalGet('admin/config/regional/language'); - $this->assertFieldChecked('edit-site-default-en', t('English is the default language.')); + $this->assertFieldChecked('edit-site-default-en', 'English is the default language.'); // Change the default language. $edit = array( 'site_default' => 'fr', ); $this->drupalPost(NULL, $edit, t('Save configuration')); - $this->assertNoFieldChecked('edit-site-default-en', t('Default language updated.')); - $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), t('Correct page redirection.')); + $this->assertNoFieldChecked('edit-site-default-en', 'Default language updated.'); + $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.'); // Check if a valid language prefix is added afrer changing the default // language. $this->drupalGet('admin/config/regional/language/detection/url'); - $this->assertFieldByXPath('//input[@name="prefix[en]"]', 'en', t('A valid path prefix has been added to the previous default language.')); + $this->assertFieldByXPath('//input[@name="prefix[en]"]', 'en', 'A valid path prefix has been added to the previous default language.'); // Check if French still has a path prefix. $this->drupalGet('admin/config/regional/language/detection/url'); - $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'fr', t('French still has a path prefix.')); + $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'fr', 'French still has a path prefix.'); + + // Check that prefix can be changed. + $edit = array( + 'prefix[fr]' => 'french', + ); + $this->drupalPost(NULL, $edit, t('Save configuration')); + $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'french', 'French path prefix has changed.'); + + // Check that prefix of non default langauge cannot be changed to + // empty string. + $edit = array( + 'prefix[en]' => '', + ); + $this->drupalPost(NULL, $edit, t('Save configuration')); + $this->assertText(t('The prefix may only be left blank for the default language.'), 'English prefix cannot be changed to empty string.'); + + // Check that prefix cannot be changed to contain a slash. + $edit = array( + 'prefix[en]' => 'foo/bar', + ); + $this->drupalPost(NULL, $edit, t('Save configuration')); + $this->assertText(t('The prefix may not contain a slash.'), 'English prefix cannot be changed to contain a slash.'); } }