diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php index cd4259a..742a7dc 100644 --- a/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -156,6 +156,14 @@ public static function validateName($name) { '@length' => self::MAX_NAME_LENGTH, ))); } + + // The name must not contain any of the following characters: + // : ? * < > " ' / \ + if (preg_match('/[:?*<>"\'\/\\\\]/', $name)) { + throw new ConfigNameException(format_string('Invalid character in Config object name @name.', array( + '@name' => $name, + ))); + } } /** @@ -427,7 +435,7 @@ public function load() { */ public function save() { // Validate the configuration object name before saving. - $this->validateName($this->name); + Config::validateName($this->name); if (!$this->isLoaded) { $this->load(); } diff --git a/core/lib/Drupal/Core/Config/ConfigNameException.php b/core/lib/Drupal/Core/Config/ConfigNameException.php new file mode 100644 index 0000000..bc4cabb --- /dev/null +++ b/core/lib/Drupal/Core/Config/ConfigNameException.php @@ -0,0 +1,13 @@ +pass($message); } - // Verify that saving a too long config object name throws an exception. + // Verify that a name longer than the maximum length causes an exception. $name = 'config_test.herman_melville.moby_dick_or_the_whale.harper_1851.now_small_fowls_flew_screaming_over_the_yet_yawning_gulf_a_sullen_white_surf_beat_against_its_steep_sides_then_all_collapsed_and_the_great_shroud_of_the_sea_rolled_on_as_it_rolled_five_thousand_years_ago'; $message = 'Expected ConfigNameException was thrown for a name longer than Config::MAX_NAME_LENGTH.'; try { @@ -132,8 +132,24 @@ function testNameValidation() { $this->pass($message); } + // Verify that disallowed characters in the name cause an exception. + $characters = $test_characters = array(':', '?', '*', '<', '>', '"', '\'', '/', '\\'); + foreach ($test_characters as $i => $c) { + try { + $name = 'namespace.object' . $c; + $config = config($name); + $config->save(); + } + catch (ConfigNameException $e) { + unset($test_characters[$i]); + } + } + $this->assertTrue(empty($test_characters), format_string('ConfigNameException was thrown for all invalid name characters: @characters', array( + '@characters' => implode(' ', $characters), + ))); + // Verify that a valid config object name can be saved. - $name = 'config.namespace'; + $name = 'namespace.object'; $message = 'ConfigNameException was not thrown for a valid object name.'; try { $config = config($name);