diff --git a/lib/classes/component.php b/lib/classes/component.php index 3ec6026ffa8..53c02414456 100644 --- a/lib/classes/component.php +++ b/lib/classes/component.php @@ -845,7 +845,7 @@ $cache = '.var_export($cache, true).'; return (bool)preg_match('/^[a-z][a-z0-9]*$/', $pluginname); } else { - return (bool)preg_match('/^[a-z](?:[a-z0-9_](?!__))*[a-z0-9]$/', $pluginname); + return (bool)preg_match('/^[a-z](?:[a-z0-9_](?!__))*[a-z0-9]+$/', $pluginname); } } diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 3e43a4a46cd..27ee39ba6d9 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -929,7 +929,7 @@ function clean_param($param, $type) { case PARAM_COMPONENT: // We do not want any guessing here, either the name is correct or not // please note only normalised component names are accepted. - if (!preg_match('/^[a-z]+(_[a-z][a-z0-9_]*)?[a-z0-9]$/', $param)) { + if (!preg_match('/^[a-z]+(_[a-z][a-z0-9_]*)?[a-z0-9]+$/', $param)) { return ''; } if (strpos($param, '__') !== false) { diff --git a/lib/tests/component_test.php b/lib/tests/component_test.php index 78bff22c568..efeff4569ff 100644 --- a/lib/tests/component_test.php +++ b/lib/tests/component_test.php @@ -198,6 +198,9 @@ class core_component_testcase extends advanced_testcase { public function test_is_valid_plugin_name() { $this->assertTrue(core_component::is_valid_plugin_name('mod', 'example1')); + $this->assertTrue(core_component::is_valid_plugin_name('mod', 'feedback360')); + $this->assertFalse(core_component::is_valid_plugin_name('mod', 'feedback_360')); + $this->assertFalse(core_component::is_valid_plugin_name('mod', '2feedback')); $this->assertFalse(core_component::is_valid_plugin_name('mod', '1example')); $this->assertFalse(core_component::is_valid_plugin_name('mod', 'example.xx')); $this->assertFalse(core_component::is_valid_plugin_name('mod', '.example')); @@ -209,6 +212,8 @@ class core_component_testcase extends advanced_testcase { $this->assertTrue(core_component::is_valid_plugin_name('tool', 'example1')); $this->assertTrue(core_component::is_valid_plugin_name('tool', 'example_x1')); $this->assertTrue(core_component::is_valid_plugin_name('tool', 'example_x1_xxx')); + $this->assertTrue(core_component::is_valid_plugin_name('tool', 'feedback360')); + $this->assertTrue(core_component::is_valid_plugin_name('tool', 'feed_back360')); $this->assertTrue(core_component::is_valid_plugin_name('tool', 'role')); $this->assertFalse(core_component::is_valid_plugin_name('tool', '1example')); $this->assertFalse(core_component::is_valid_plugin_name('tool', 'example.xx')); diff --git a/lib/tests/moodlelib_test.php b/lib/tests/moodlelib_test.php index 04008997e01..607a1436f45 100644 --- a/lib/tests/moodlelib_test.php +++ b/lib/tests/moodlelib_test.php @@ -482,6 +482,8 @@ class core_moodlelib_testcase extends advanced_testcase { $this->assertSame('forum', clean_param('forum', PARAM_COMPONENT)); $this->assertSame('user', clean_param('user', PARAM_COMPONENT)); $this->assertSame('rating', clean_param('rating', PARAM_COMPONENT)); + $this->assertSame('feedback360', clean_param('feedback360', PARAM_COMPONENT)); + $this->assertSame('mod_feedback360', clean_param('mod_feedback360', PARAM_COMPONENT)); $this->assertSame('', clean_param('mod_2something', PARAM_COMPONENT)); $this->assertSame('', clean_param('2mod_something', PARAM_COMPONENT)); $this->assertSame('', clean_param('mod_something_xx', PARAM_COMPONENT)); @@ -501,6 +503,7 @@ class core_moodlelib_testcase extends advanced_testcase { public function test_is_valid_plugin_name() { $this->assertTrue(is_valid_plugin_name('forum')); $this->assertTrue(is_valid_plugin_name('forum2')); + $this->assertTrue(is_valid_plugin_name('feedback360')); $this->assertTrue(is_valid_plugin_name('online_users')); $this->assertTrue(is_valid_plugin_name('blond_online_users')); $this->assertFalse(is_valid_plugin_name('online__users')); @@ -517,6 +520,7 @@ class core_moodlelib_testcase extends advanced_testcase { // Please note the cleaning of plugin names is very strict, no guessing here. $this->assertSame('forum', clean_param('forum', PARAM_PLUGIN)); $this->assertSame('forum2', clean_param('forum2', PARAM_PLUGIN)); + $this->assertSame('feedback360', clean_param('feedback360', PARAM_PLUGIN)); $this->assertSame('online_users', clean_param('online_users', PARAM_PLUGIN)); $this->assertSame('blond_online_users', clean_param('blond_online_users', PARAM_PLUGIN)); $this->assertSame('', clean_param('online__users', PARAM_PLUGIN)); @@ -535,6 +539,7 @@ class core_moodlelib_testcase extends advanced_testcase { $this->assertSame('something2', clean_param('something2', PARAM_AREA)); $this->assertSame('some_thing', clean_param('some_thing', PARAM_AREA)); $this->assertSame('some_thing_xx', clean_param('some_thing_xx', PARAM_AREA)); + $this->assertSame('feedback360', clean_param('feedback360', PARAM_AREA)); $this->assertSame('', clean_param('_something', PARAM_AREA)); $this->assertSame('', clean_param('something_', PARAM_AREA)); $this->assertSame('', clean_param('2something', PARAM_AREA));