Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-74403

[jython] Extract inline script blocks in WEB-INF/classes/org/jvnet/hudson/plugins/Jython/config.jelly

    • Icon: Task Task
    • Resolution: Unresolved
    • Icon: Minor Minor
    • jython-plugin

      Problems

      == Inline Script Block
      Line: 7
      ----
      <script type="text/javascript">
              <![CDATA[
                // TODO revisit - adds listeners to prepare syntax highlight editor
                // for build step removal (without this, the project won't save).
                // This is invoked in two places - CodeMirror#fromTextArea(...) and
                // when the editor's onFocus event occurs.
                addNodeRemovalListener = function(editor) {
                  if (typeof editor.removeListenerAdded == 'undefined') {
                    var buildStepNode = editor.getWrapperElement().
                      parentNode.parentNode.parentNode.parentNode.parentNode;
                    buildStepNode.dragging = false;
                    buildStepNode.addEventListener(
                      "DOMNodeRemovedFromDocument",
                      function(event) {
                        // Switch editor back to non-syntax highlighted mode when the
                        // build step is removed.
                        // However don't do this while the build step is being dragged
                        // (i.e., when it's being re-ordered).
                        if (!buildStepNode.dragging) {
                          editor.toTextArea()
                        }
                      },
                      false
                    )
                    buildStepNode.addEventListener(
                      "mousedown",
                      function(event) {
                        // Indicates that this build step is being dragged.
                        buildStepNode.dragging = true
                      },
                      false
                    )
                    buildStepNode.addEventListener(
                      "mouseup",
                      function(event) {
                        // Indicates that this build step is no longer being dragged.
                        buildStepNode.dragging = false
                      },
                      false
                    )
      
                    editor.removeListenerAdded = true
                  }
                }
                
                // TODO revisit - onChange listener to manually update the source
                // <textarea> so that scripts in newly added build steps get saved.
                updateTextArea = function(editor) {
                  editor.getWrapperElement().previousSibling.value=editor.getValue()
                }
              ]]>
              </script>
      ----
      
      == Inline Script Block
      Line: 71
      ----
      <script type="text/javascript">
              <![CDATA[
                // TODO revisit - overrides CodeMirror#fromTextArea(...) to invoke
                // addNodeRemovalListener on new editors (applies to existing build
                // steps in project - for new build steps, this is applied during the
                // editors onFocus())
                if (typeof CodeMirror != 'undefined' &&
                    typeof CodeMirror.hackApplied == 'undefined') {
                  var origFromTextArea = CodeMirror.fromTextArea
                  CodeMirror.fromTextArea = function(textArea, options) {
                    var editor = origFromTextArea(textArea, options)
                    addNodeRemovalListener(editor)
                    return editor
                  }
                  
                  CodeMirror.hackApplied = true
                }
              ]]>
              </script>
      ----
      

      Solution

      https://www.jenkins.io/doc/developer/security/csp/#inline-javascript-blocks

          [JENKINS-74403] [jython] Extract inline script blocks in WEB-INF/classes/org/jvnet/hudson/plugins/Jython/config.jelly

          Basil Crow created issue -
          Basil Crow made changes -
          Description Original: h4. Problems

          {noformat}
          == Inline Script Block
          Line: 7
          ----
          <script type="text/javascript">
                  <![CDATA[
                    // TODO revisit - adds listeners to prepare syntax highlight editor
                    // for build step removal (without this, the project won't save).
                    // This is invoked in two places - CodeMirror#fromTextArea(...) and
                    // when the editor's onFocus event occurs.
                    addNodeRemovalListener = function(editor) {
                      if (typeof editor.removeListenerAdded == 'undefined') {
                        var buildStepNode = editor.getWrapperElement().
                          parentNode.parentNode.parentNode.parentNode.parentNode;
                        buildStepNode.dragging = false;
                        buildStepNode.addEventListener(
                          "DOMNodeRemovedFromDocument",
                          function(event) {
                            // Switch editor back to non-syntax highlighted mode when the
                            // build step is removed.
                            // However don't do this while the build step is being dragged
                            // (i.e., when it's being re-ordered).
                            if (!buildStepNode.dragging) {
                              editor.toTextArea()
                            }
                          },
                          false
                        )
                        buildStepNode.addEventListener(
                          "mousedown",
                          function(event) {
                            // Indicates that this build step is being dragged.
                            buildStepNode.dragging = true
                          },
                          false
                        )
                        buildStepNode.addEventListener(
                          "mouseup",
                          function(event) {
                            // Indicates that this build step is no longer being dragged.
                            buildStepNode.dragging = false
                          },
                          false
                        )

                        editor.removeListenerAdded = true
                      }
                    }
                    
                    // TODO revisit - onChange listener to manually update the source
                    // <textarea> so that scripts in newly added build steps get saved.
                    updateTextArea = function(editor) {
                      editor.getWrapperElement().previousSibling.value=editor.getValue()
                    }
                  ]]>
                  </script>
          ----

          == Inline Script Block
          Line: 71
          ----
          <script type="text/javascript">
                  <![CDATA[
                    // TODO revisit - overrides CodeMirror#fromTextArea(...) to invoke
                    // addNodeRemovalListener on new editors (applies to existing build
                    // steps in project - for new build steps, this is applied during the
                    // editors onFocus())
                    if (typeof CodeMirror != 'undefined' &&
                        typeof CodeMirror.hackApplied == 'undefined') {
                      var origFromTextArea = CodeMirror.fromTextArea
                      CodeMirror.fromTextArea = function(textArea, options) {
                        var editor = origFromTextArea(textArea, options)
                        addNodeRemovalListener(editor)
                        return editor
                      }
                      
                      CodeMirror.hackApplied = true
                    }
                  ]]>
                  </script>
          ----

          == Inline Script Block
          Line: 7
          ----
          <script type="text/javascript">
                  <![CDATA[
                    // TODO revisit - adds listeners to prepare syntax highlight editor
                    // for build step removal (without this, the project won't save).
                    // This is invoked in two places - CodeMirror#fromTextArea(...) and
                    // when the editor's onFocus event occurs.
                    addNodeRemovalListener = function(editor) {
                      if (typeof editor.removeListenerAdded == 'undefined') {
                        var buildStepNode = editor.getWrapperElement().
                          parentNode.parentNode.parentNode.parentNode.parentNode;
                        buildStepNode.dragging = false;
                        buildStepNode.addEventListener(
                          "DOMNodeRemovedFromDocument",
                          function(event) {
                            // Switch editor back to non-syntax highlighted mode when the
                            // build step is removed.
                            // However don't do this while the build step is being dragged
                            // (i.e., when it's being re-ordered).
                            if (!buildStepNode.dragging) {
                              editor.toTextArea()
                            }
                          },
                          false
                        )
                        buildStepNode.addEventListener(
                          "mousedown",
                          function(event) {
                            // Indicates that this build step is being dragged.
                            buildStepNode.dragging = true
                          },
                          false
                        )
                        buildStepNode.addEventListener(
                          "mouseup",
                          function(event) {
                            // Indicates that this build step is no longer being dragged.
                            buildStepNode.dragging = false
                          },
                          false
                        )

                        editor.removeListenerAdded = true
                      }
                    }
                    
                    // TODO revisit - onChange listener to manually update the source
                    // <textarea> so that scripts in newly added build steps get saved.
                    updateTextArea = function(editor) {
                      editor.getWrapperElement().previousSibling.value=editor.getValue()
                    }
                  ]]>
                  </script>
          ----

          == Inline Script Block
          Line: 71
          ----
          <script type="text/javascript">
                  <![CDATA[
                    // TODO revisit - overrides CodeMirror#fromTextArea(...) to invoke
                    // addNodeRemovalListener on new editors (applies to existing build
                    // steps in project - for new build steps, this is applied during the
                    // editors onFocus())
                    if (typeof CodeMirror != 'undefined' &&
                        typeof CodeMirror.hackApplied == 'undefined') {
                      var origFromTextArea = CodeMirror.fromTextArea
                      CodeMirror.fromTextArea = function(textArea, options) {
                        var editor = origFromTextArea(textArea, options)
                        addNodeRemovalListener(editor)
                        return editor
                      }
                      
                      CodeMirror.hackApplied = true
                    }
                  ]]>
                  </script>
          ----
          {noformat}

          h4. Solution

          [https://www.jenkins.io/doc/developer/security/csp/#inline-javascript-blocks]
          New: h4. Problems

          {noformat}
          == Inline Script Block
          Line: 7
          ----
          <script type="text/javascript">
                  <![CDATA[
                    // TODO revisit - adds listeners to prepare syntax highlight editor
                    // for build step removal (without this, the project won't save).
                    // This is invoked in two places - CodeMirror#fromTextArea(...) and
                    // when the editor's onFocus event occurs.
                    addNodeRemovalListener = function(editor) {
                      if (typeof editor.removeListenerAdded == 'undefined') {
                        var buildStepNode = editor.getWrapperElement().
                          parentNode.parentNode.parentNode.parentNode.parentNode;
                        buildStepNode.dragging = false;
                        buildStepNode.addEventListener(
                          "DOMNodeRemovedFromDocument",
                          function(event) {
                            // Switch editor back to non-syntax highlighted mode when the
                            // build step is removed.
                            // However don't do this while the build step is being dragged
                            // (i.e., when it's being re-ordered).
                            if (!buildStepNode.dragging) {
                              editor.toTextArea()
                            }
                          },
                          false
                        )
                        buildStepNode.addEventListener(
                          "mousedown",
                          function(event) {
                            // Indicates that this build step is being dragged.
                            buildStepNode.dragging = true
                          },
                          false
                        )
                        buildStepNode.addEventListener(
                          "mouseup",
                          function(event) {
                            // Indicates that this build step is no longer being dragged.
                            buildStepNode.dragging = false
                          },
                          false
                        )

                        editor.removeListenerAdded = true
                      }
                    }
                    
                    // TODO revisit - onChange listener to manually update the source
                    // <textarea> so that scripts in newly added build steps get saved.
                    updateTextArea = function(editor) {
                      editor.getWrapperElement().previousSibling.value=editor.getValue()
                    }
                  ]]>
                  </script>
          ----

          == Inline Script Block
          Line: 71
          ----
          <script type="text/javascript">
                  <![CDATA[
                    // TODO revisit - overrides CodeMirror#fromTextArea(...) to invoke
                    // addNodeRemovalListener on new editors (applies to existing build
                    // steps in project - for new build steps, this is applied during the
                    // editors onFocus())
                    if (typeof CodeMirror != 'undefined' &&
                        typeof CodeMirror.hackApplied == 'undefined') {
                      var origFromTextArea = CodeMirror.fromTextArea
                      CodeMirror.fromTextArea = function(textArea, options) {
                        var editor = origFromTextArea(textArea, options)
                        addNodeRemovalListener(editor)
                        return editor
                      }
                      
                      CodeMirror.hackApplied = true
                    }
                  ]]>
                  </script>
          ----
          {noformat}

          h4. Solution

          [https://www.jenkins.io/doc/developer/security/csp/#inline-javascript-blocks]

            Unassigned Unassigned
            basil Basil Crow
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: