MDL-76362 core: plugin names must be strings to be valid

This commit is contained in:
Andrew Nicols 2023-01-06 22:30:16 +08:00
parent e068f2284f
commit 93ab932211
2 changed files with 8 additions and 3 deletions

View File

@ -1001,10 +1001,9 @@ $cache = '.var_export($cache, true).';
}
// Modules MUST NOT have any underscores,
// component normalisation would break very badly otherwise!
return (bool)preg_match('/^[a-z][a-z0-9]*$/', $pluginname);
return !is_null($pluginname) && (bool) preg_match('/^[a-z][a-z0-9]*$/', $pluginname);
} else {
return (bool)preg_match('/^[a-z](?:[a-z0-9_](?!__))*[a-z0-9]+$/', $pluginname ?? '');
return !is_null($pluginname) && (bool) preg_match('/^[a-z](?:[a-z0-9_](?!__))*[a-z0-9]+$/', $pluginname);
}
}

View File

@ -257,6 +257,12 @@ class component_test extends advanced_testcase {
[['tool', '_example'], false],
[['tool', 'example_'], false],
[['tool', 'example__x1'], false],
// Some invalid cases.
[['mod', null], false],
[['mod', ''], false],
[['tool', null], false],
[['tool', ''], false],
];
}