mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 20:42:22 +02:00
MDL-48542 user_menu: Handle invalid strings better
This commit is contained in:
parent
af9a7937cc
commit
06c2753115
@ -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),
|
||||
|
10
user/lib.php
10
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];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user