MDL-41953 allow plugin names to end with multiple digits

This commit is contained in:
Petr Škoda 2013-10-04 15:56:37 +02:00
parent 89376590c0
commit a41d1ca0ce
4 changed files with 12 additions and 2 deletions

View File

@ -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);
}
}

View File

@ -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) {

View File

@ -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'));

View File

@ -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));