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

Bad array looping in autolink.js from glossary filter.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.3, 2.4
    • Fix Version/s: None
    • Component/s: Glossary
    • Labels:
      None
    • Affected Branches:
      MOODLE_23_STABLE, MOODLE_24_STABLE

      Description

      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++) {
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              moodle.com moodle.com
              Reporter:
              esteve Esteve Badia
              Participants:
              Component watchers:
              Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated: