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

Search in mod_data breaks the html if links are used

    XMLWordPrintable

    Details

    • Affected Branches:
      MOODLE_39_STABLE

      Description

      Hello,

      We have a database activity with element with url fields. We then use the template to render those elements and generates html with images , etc ...

       

      When we search a string that is inside the url field, it breaks the whole html because it inserts the highlight span inside the url.

       

      The solution is to call the highlight data_print_template function not on each field but in the end of the function in lib. php.

       

      Here is a diff that fixes the problem :

       

       

      diff --git a/mod/data/lib.php b/mod/data/lib.php
      index 4e40e8e420..34f0ae8cab 100644
      --- a/mod/data/lib.php
      +++ b/mod/data/lib.php
      @@ -1410,7 +1410,8 @@ function data_print_template($template, $records, $data, $search='', $page=0, $r
       // Then we generate strings to replace for normal tags
       foreach ($fields as $field) {
       $patterns[]='[['.$field->field->name.']]';
      - $replacement[] = highlight($search, $field->display_browse_field($record->id, $template));
      + //$replacement[] = highlight($search, $field->display_browse_field($record->id, $template));
      + $replacement[] = $field->display_browse_field($record->id, $template);
       }
      $canmanageentries = has_capability('mod/data:manageentries', $context);
      @@ -1548,7 +1549,7 @@ function data_print_template($template, $records, $data, $search='', $page=0, $r
      // actual replacement of the tags
       $newtext = str_ireplace($patterns, $replacement, $data->{$template});
      -
      + $newtext = highlight($search, $newtext);
       // no more html formatting and filtering - see MDL-6635
       if ($return) {
       return $newtext;
      

      Best regards.

       

      Noel

       

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            ndieschburg Noel Dieschburg
            Participants:
            Component watchers:
            Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias, Sujith Haridasan
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 5 minutes
                5m