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

Can not display a label (resource) which has HTML-tag strings only

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 1.9.2
    • 1.9.1
    • Resource
    • None
    • MOODLE_19_STABLE
    • MOODLE_19_STABLE

      A Label which consists of HTML-tag strings only (eg. <hr/>) isn't displayed on a course topic field.

      Notice: Undefined index: 847 in C:\xampplite\htdocs\mech\moodle\course\lib.php on line 1344
      Notice: Trying to get property of non-object in C:\xampplite\htdocs\mech\moodle\course\lib.php on line 1344

      The cause of this problem is that the name field of the label in mdl_label is blank.

      In mod/label/lib.php, HTML tags of the label content is eliminated by strip_tags() to generate a name of the label.
      If the content of the label consisted of HTML-tag only, the name of the label would be blank.

      I propose a patch as follows.
      ------------------------
      function label_add_instance($label) {
      /// Given an object containing all the necessary data,
      /// (defined by the form in mod.html) this function
      /// will create a new instance and return the id number
      /// of the new instance.
      $textlib = textlib_get_instance();

      $label->name = addslashes(strip_tags(format_string(stripslashes($label->content),true)));
      // (Shirai): Add from here
      if (strlen($label->name) == 0) $label->name = 'noname';
      // (Shirai): Add to here
      if ($textlib->strlen($label->name) > LABEL_MAX_NAME_LENGTH)

      { $label->name = $textlib->substr($label->name, 0, LABEL_MAX_NAME_LENGTH)."..."; }
      $label->timemodified = time();

      return insert_record("label", $label);
      }

      function label_update_instance($label) {
      /// Given an object containing all the necessary data,
      /// (defined by the form in mod.html) this function
      /// will update an existing instance with new data.
      $textlib = textlib_get_instance();

      $label->name = addslashes(strip_tags(format_string(stripslashes($label->content),true)));
      // (Shirai): Add from here
      if (strlen($label->name) == 0) $label->name = 'noname';
      // (Shirai): Add to here
      if ($textlib->strlen($label->name) > LABEL_MAX_NAME_LENGTH) { $label->name = $textlib->substr($label->name, 0, LABEL_MAX_NAME_LENGTH)."..."; }

      $label->timemodified = time();
      $label->id = $label->instance;

      return update_record("label", $label);
      }

            skodak Petr Skoda
            shirai Tatsuya Shirai
            Dongsheng Cai Dongsheng Cai
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

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