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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.9.1
    • Fix Version/s: 1.9.2
    • Component/s: Resource
    • Labels:
      None
    • Affected Branches:
      MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE

      Description

      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);
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                skodak Petr Skoda
                Reporter:
                shirai Tatsuya Shirai
                Tester:
                Dongsheng Cai
                Participants:
                Component watchers:
                Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  11/Jul/08