MDL-48542 user_menu: Handle invalid strings better

This commit is contained in:
Andrew Nicols 2015-01-28 15:33:46 +08:00
parent af9a7937cc
commit 06c2753115
2 changed files with 15 additions and 3 deletions

View File

@ -38,6 +38,14 @@ class core_user_menu_testcase extends advanced_testcase {
array('-----', 0, 0),
array('_____', 0, 0),
array('test', 0, 0),
array('#Garbage#', 0, 0),
// These are valid but have an invalid string identifiers or components. They will still produce a menu
// item, and no exception should be thrown.
array('#my1files,moodle|/user/files.php|download', 1, 0),
array('#my1files,moodleakjladf|/user/files.php|download', 1, 0),
array('#my1files,a/b|/user/files.php|download', 1, 0),
array('#my1files,#b|/user/files.php|download', 1, 0),
// These are unusual, but valid and will generate a menu entry (no filler).
array('-|-|-|-', 1, 0),

View File

@ -657,9 +657,13 @@ function user_convert_text_to_menu_items($text, $page) {
// Name processing.
$namebits = explode(',', $bits[0], 2);
if (count($namebits) == 2) {
// Treat this as a language string.
$child->title = get_string($namebits[0], $namebits[1]);
} else {
// Check the validity of the identifier part of the string.
if (clean_param($namebits[0], PARAM_STRINGID) !== '') {
// Treat this as a language string.
$child->title = get_string($namebits[0], $namebits[1]);
}
}
if (empty($child->title)) {
// Use it as is, don't even clean it.
$child->title = $bits[0];
}