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

Bad array looping in autolink.js from glossary filter.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Do
    • Icon: Minor Minor
    • None
    • 2.3, 2.4
    • Glossary
    • None
    • MOODLE_23_STABLE, MOODLE_24_STABLE

      In line 71 of file /filter/glossary/yui/autolinker.js there is a looping through an array:

      for (key in data.entries) {
      

      This is a bad practice for multiple reasons (http://stackoverflow.com/questions/500504/javascript-for-in-with-arrays).

      Actually, when using the comercial plugin WIRIS quizzes, the glossary shows 4 popups instead of 1 popup when clicking to the word in question. This is because this plugin has added 3 functions to the array prototype and this way of iterating over the array is iterating in fact over the array object methods and properies.

      As we can't assure whether some plugins add methods to the array prototype, we should use the standard way to iterate over the array (which is faster too).

      So it would be easily fixed changing this line 71 by:

      for (var key = 0; key < data.entries.length; key++) {
      

            moodle.com Moodle HQ
            esteve Esteve Badia
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

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