Skip to content

Commit

Permalink
MDL-48542 user_menu: Handle invalid strings better
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Jan 28, 2015
1 parent a72f2cc commit 2ceba91
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 8 additions & 0 deletions lib/tests/user_menu_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ public function custom_user_menu_data() {
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),
Expand Down
10 changes: 7 additions & 3 deletions user/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down

0 comments on commit 2ceba91

Please sign in to comment.