diff --git a/lib/tests/user_menu_test.php b/lib/tests/user_menu_test.php index dbabd2ba2f4..af9335e10da 100644 --- a/lib/tests/user_menu_test.php +++ b/lib/tests/user_menu_test.php @@ -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), diff --git a/user/lib.php b/user/lib.php index 0689e18a178..4ba6d6119f2 100644 --- a/user/lib.php +++ b/user/lib.php @@ -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]; }