Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-4532

Javascript generated by s:doubleselect has global variables that can interfer with the rest of the app

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.20
    • 2.5
    • Plugin - Tags

    Description

      In the JavaScript code generated by the s:doubleselect tag (and, possibly other tags), there are for loops using the following format :

      for (m = ObservationForm_observation_countryKeyTemp.options.length - 1; m >= 0; m--) {
                  ObservationForm_observation_countryKeyTemp.options[m] = null; 

      The variable m is never defined before that. So this creates a globally scoped m variable that can interfere with other JavaScript code.

      In my case it interfered with library code that is processed with a minifyer (I think in this case it is Google Closure Compiler) and contains a lot of one-letter variable name, such as... m.

      So I got the following error :

      Uncaught TypeError: number is not a function
      

      Which was difficult to trace since the code was minified. If the code was not minified, then the error did not happen any more.

      I believe it would be enough to just use the var keyword in the loop definition to remove this problem :

      for (var m = ObservationForm_observation_countryKeyTemp.options.length - 1; m >= 0; m--) {
                  ObservationForm_observation_countryKeyTemp.options[m] = null; 

      Attachments

        Activity

          People

            jogep Johannes Geppert
            pierrehenry Pierre Henry
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: