Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-83688

Naming a grade category "0" causes an error on the gradebook setup page

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 4.4.5, 4.5.1
    • Gradebook

      Editing a gradebook category to change its name to the string "0" causes the error 

      Exception - Array key (name or level) missing from 3rd param of grade_edit_tree_column_name::get_category_cell($category, $levelclass, $params).
       
      Stack trace:  
      line 823 of /grade/edit/tree/lib.php: 
      Exception thrown
      line 288 of /grade/edit/tree/lib.php: call to grade_edit_tree_column_name->get_category_cell()
      line 86 of /grade/edit/tree/lib.php: call to grade_edit_tree->build_html_tree()
      line 93 of /grade/edit/tree/index.php: call to grade_edit_tree->__construct()

      To reproduce:

      • Create a new course
      • Go to Grades > Gradebook Setup
      • Rename an existing or new category to "0"

      The conditional that causes this error uses the empty() function to check the name parameter of the category, which will return true for the string "0." This conditional is quite old in the code but it appears that Moodle used to mutate the name property to prepend a folder icon, which would result in this error not being thrown. I checked with Moodle 3.5 and the error does not appear due to this folder icon HTML being added to the string. I'm not sure how recently the code was changed to no longer add this icon to the property, but I imagine that is when this bug first appeared. Maybe 4.0?

      Anyway, I'm attaching patches for 4.4 and 4.5 to change the conditional to check isset() rather than empty(), which will not cause an error for the string "0." If there is some side-effect of this that I'm missing, let me know and I can make changes.

            bryce.yoder@moodle.com Bryce Yoder
            bryce.yoder@moodle.com Bryce Yoder
            Paul Holden Paul Holden
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.