Repository: ManageIQ/manageiq-ui-classic
Pull request #9438: Revert jquery 3.7.1 upgrade
Author: login: jrafanie
Labels: name: bug
name: explorers
name: spassky/backported
Created: 2025-05-16T22:07:16Z | Merged: 2025-05-20T19:56:55Z

Fixes https://github.com/ManageIQ/manageiq-ui-classic/issues/9433

<!--
1. Describe what this Pull Request does and why you think it is needed.
   If this PR includes UI or CLI changes, please include Before/After screenshots
   If this PR includes performance changes, please include Before/After metrics showing improvement.
-->

<!--
2. If this fixes an existing issue, please specify in `Fixes #<id>` format
   (As described in https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue)
-->

<!--
3. Ask @miq-bot to apply a scope label (bug, enhancement, etc) and any additional reviewers or assignees.
   (As described in https://github.com/ManageIQ/miq_bot#requested-tasks)
   e.g. `@miq-bot add-label label_name`
        `@miq-bot add-reviewer @name`
-->



Diff:
diff --git a/.yarnrc.yml b/.yarnrc.yml
index 70465b170c6..da8a9d587c5 100644
--- a/.yarnrc.yml
+++ b/.yarnrc.yml
@@ -19,5 +19,10 @@ npmAuditExcludePackages:
 # pending | moderate | GHSA-9mvj-f7w8-pvh2 | bootstrap >=2.0.0 <=3.4.1 | 3.4.1 brought in by eonasdan-bootstrap-datetimepicker@virtual:6557af66f1a3f9d81b30dd080e0c619c011728fa0bded31959e34111c8a06d5f82c760d19a3100c59f98831cc7e73d48a91c41d41de6db59b14a282cb6169d79#npm:4.17.49
 - bootstrap-sass
 # pending | moderate | GHSA-9mvj-f7w8-pvh2 | bootstrap-sass >=2.0.0 <=3.4.3 | 3.4.3 brought in by patternfly@npm:3.59.5
+- jquery
+# pending | moderate | GHSA-rmxg-73gg-4p98 | jquery >=1.12.3 <3.0.0 | 2.2.4 brought in by manageiq-ui-classic@workspace:.
+# pending | moderate | GHSA-gxr4-xjj5-5px2 | jquery >=1.2.0 <3.5.0  | 2.2.4, 3.4.1 brought in by manageiq-ui-classic@workspace:., patternfly@npm:3.59.5
+# pending | moderate | GHSA-6c3j-c64m-qhgq | jquery >=1.1.4 <3.4.0  | 2.2.4 brought in by manageiq-ui-classic@workspace:.
+# pending | moderate | GHSA-jpcq-cgw6-v4j6 | jquery >=1.0.3 <3.5.0  | 2.2.4, 3.4.1 brought in by manageiq-ui-classic@workspace:., patternfly@npm:3.59.5
 
 yarnPath: .yarn/releases/yarn-4.9.1.cjs
diff --git a/app/javascript/oldjs/import.js b/app/javascript/oldjs/import.js
index b1cb86d150b..fda3f3308fd 100644
--- a/app/javascript/oldjs/import.js
+++ b/app/javascript/oldjs/import.js
@@ -65,7 +65,8 @@ window.ImportSetup = {
   listenForGitPostMessages: function() {
     window.addEventListener('message', function(event) {
       var messageData = event.data.message;
-      if (messageData && messageData.level === 'error') {
+
+      if (messageData.level === 'error') {
         showErrorMessage(messageData.message);
         $('#git-url-import').prop('disabled', null);
       } else if (event.data.git_branches || event.data.git_tags) {
diff --git a/app/javascript/oldjs/jquery_overrides.js b/app/javascript/oldjs/jquery_overrides.js
index 8365817dd27..526ce0d4803 100644
--- a/app/javascript/oldjs/jquery_overrides.js
+++ b/app/javascript/oldjs/jquery_overrides.js
@@ -24,19 +24,6 @@ jQuery.jsonPayload = function(text, fallback) {
 };
 
 $.ajaxSetup({
-  /* Define two script converters:
-
-  1) script - This is the original converter to evaluate scripts for successful responses.
-  2) miq_script - Define a duplicate but differently named script converter whose purpose is to
-  evaluate scripts for unsuccessful ajax responses.  jQuery 3.5.0 changed the behavior of the script
-  converter, replacing it with a no-op converter for scripts found in unsuccessful ajax responses.
-  Successful responses would continue to be evaluated as previously.
-  See: https://github.com/jquery/jquery/commit/da3dd85b63c4e3a6a768132c2a83a1a6eec24840
-
-  Due to this change starting in 3.5.0, we define a new type of script we can set as the dataType
-  so it's evaluated in the event of unsuccessful responses such as the SSO 401 unauthorized
-  issue we attempted to fix in #9410 and subsequently completed in #9426.
-  */
   accepts: {
     json: 'text/javascript, application/javascript, application/ecmascript, application/x-ecmascript',
   },
@@ -49,15 +36,6 @@ $.ajaxSetup({
         return jQuery.parseJSON(text);
       });
     }),
-    'text miq_script': logError(function(text) {
-      if (text.match(/^{/)) {
-        return jQuery.jsonPayload(text, function(text) {
-          return text;
-        });
-      }  // JavaScript payload
-      jQuery.globalEval(text.slice('throw "error";'.length));
-      return text;
-    }),
     'text script': logError(function(text) {
       if (text.match(/^{/)) {
         return jQuery.jsonPayload(text, function(text) {
diff --git a/app/javascript/oldjs/miq_application.js b/app/javascript/oldjs/miq_application.js
index 1332b0463fb..a3bdfa3c8eb 100644
--- a/app/javascript/oldjs/miq_application.js
+++ b/app/javascript/oldjs/miq_application.js
@@ -1091,8 +1091,8 @@ window.miqJqueryRequest = function(url, options) {
   };
 
   if (options.dataType === undefined) {
-    ajax_options.accepts = { miq_script: `*/*;q=0.5, ${$.ajaxSettings.accepts.script}` };
-    ajax_options.dataType = 'miq_script';
+    ajax_options.accepts = { script: `*/*;q=0.5, ${$.ajaxSettings.accepts.script}` };
+    ajax_options.dataType = 'script';
   }
 
   // copy selected options over
diff --git a/app/javascript/spec/ops-tenant-form/ops-tenant-form.spec.js b/app/javascript/spec/ops-tenant-form/ops-tenant-form.spec.js
index cd4fc687254..20a9e97b353 100644
--- a/app/javascript/spec/ops-tenant-form/ops-tenant-form.spec.js
+++ b/app/javascript/spec/ops-tenant-form/ops-tenant-form.spec.js
@@ -52,9 +52,6 @@ describe('OpstTenantForm', () => {
   });
 
   it('should mount and set initialValues', async(done) => {
-    fetchMock.getOnce('/api/tenants?filter[]=name=&expand=resources', {
-      resources: [],
-    });
     fetchMock.getOnce('/api/tenants/123?expand=resources&attributes=name,description,use_config_for_attributes,ancestry,divisible', {
       name: 'foo',
     });
diff --git a/config/jest.setup.js b/config/jest.setup.js
index c6e84747e98..860233158e3 100644
--- a/config/jest.setup.js
+++ b/config/jest.setup.js
@@ -53,11 +53,7 @@ ManageIQ.redux.store.injectReducers();
 
 Object.defineProperty(Array.prototype, 'flat', {
     value: function(depth = 1) {
-      let array = this;
-      if (typeof this === 'object') {
-        array = Object.keys(this).map((key) => this[key])
-      }
-      return array.reduce(function (flat, toFlatten) {
+      return this.reduce(function (flat, toFlatten) {
         return flat.concat((Array.isArray(toFlatten) && (depth>1)) ? toFlatten.flat(depth-1) : toFlatten);
       }, []);
     }
diff --git a/package.json b/package.json
index 6aec5022abe..789d40ab1a3 100644
--- a/package.json
+++ b/package.json
@@ -72,7 +72,7 @@
     "eonasdan-bootstrap-datetimepicker": "~4.17.49",
     "es6-shim": "~0.35.3",
     "history": "^4.7.2",
-    "jquery": "~3.7.1",
+    "jquery": "~2.2.4",
     "jquery-ui": "~1.13.2",
     "jquery-ujs": "~1.2.2",
     "jquery.hotkeys": "~0.1.0",
@@ -190,7 +190,6 @@
     "cross-spawn": "~7.0.5",
     "decode-uri-component": "^0.2.2",
     "express": "^4.18.2",
-    "jquery": "~3.7.1",
     "lodash": "~4.17.21",
     "minimatch": "~3.1.2",
     "moment": "^2.30.1",
diff --git a/spec/javascripts/automate_import_export_spec.js b/spec/javascripts/automate_import_export_spec.js
index 9afa9e5c2d1..ea918b32cf3 100644
--- a/spec/javascripts/automate_import_export_spec.js
+++ b/spec/javascripts/automate_import_export_spec.js
@@ -263,8 +263,8 @@ describe('Automate', function() {
         it('refreshes the selectpicker for git-branches and git-tags', function() {
           Automate.renderGitImport(['branches'], ['tags'], '123', {message: 'the message', level: 'warning'});
           expect($.fn.selectpicker.calls.allArgs()).toEqual([['refresh'], ['refresh']]);
-          expect($.fn.selectpicker.calls.first().object[0].className).toEqual('git-branches');
-          expect($.fn.selectpicker.calls.mostRecent().object[0].className).toEqual('git-tags');
+          expect($.fn.selectpicker.calls.first().object.selector).toEqual('select.git-branches');
+          expect($.fn.selectpicker.calls.mostRecent().object.selector).toEqual('select.git-tags');
         });
       });
 
diff --git a/spec/javascripts/import_spec.js b/spec/javascripts/import_spec.js
index a3d67cf67a6..f8967105f89 100644
--- a/spec/javascripts/import_spec.js
+++ b/spec/javascripts/import_spec.js
@@ -120,6 +120,7 @@ describe('import.js', function() {
 
           it('disables the git-url-import', function() {
             expect($.fn.prop).toHaveBeenCalledWith('disabled', null);
+            expect($.fn.prop.calls.mostRecent().object.selector).toEqual('#git-url-import');
           });
 
           it('turns the spinner off', function() {
diff --git a/spec/javascripts/miq_application_spec.js b/spec/javascripts/miq_application_spec.js
index 1f30f0b44bf..0785091c146 100644
--- a/spec/javascripts/miq_application_spec.js
+++ b/spec/javascripts/miq_application_spec.js
@@ -6,7 +6,7 @@ describe('miq_application.js', function() {
     });
 
     it('verify serialize method doesnt convert line feed value to windows line feed', function() {
-      expect(miqSerializeForm('form_div')).toEqual('method_data=new%20line%20added%0A%0A');
+      expect(miqSerializeForm('form_div')).toEqual("method_data=new+line+added%0A%0A");
     });
   });
 
diff --git a/spec/javascripts/services/miq_service_spec.js b/spec/javascripts/services/miq_service_spec.js
index 7616c6f9659..5d9e6ddcb55 100644
--- a/spec/javascripts/services/miq_service_spec.js
+++ b/spec/javascripts/services/miq_service_spec.js
@@ -57,6 +57,7 @@ describe('miqService', function() {
 
     it('refreshes all selects', function() {
       testService.refreshSelectpicker();
+      expect($.fn.selectpicker.calls.mostRecent().object.selector).toEqual('select');
       expect($.fn.selectpicker.calls.mostRecent().args[0]).toEqual('refresh');
     });
   });
diff --git a/yarn.lock b/yarn.lock
index 477b365e1e5..56a8cb5f624 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -10779,13 +10779,27 @@ __metadata:
   languageName: node
   linkType: hard
 
-"jquery@npm:~3.7.1":
+"jquery@npm:1.8 - 4, jquery@npm:>=1.7, jquery@npm:>=1.7.0, jquery@npm:>=1.8.0 <4.0.0, jquery@npm:>=1.9.0, jquery@npm:>=3.4.0 <4.0.0, jquery@npm:^3.4.1, jquery@npm:^3.5.1":
   version: 3.7.1
   resolution: "jquery@npm:3.7.1"
   checksum: 10/17be9929f5fa37697d9848284f0d108c543318ef79ec794e130cd0c49f6c050d60c803a69e8cfa16fa19f5ff7cdb814a6905cceab0831186560c65ed113cd579
   languageName: node
   linkType: hard
 
+"jquery@npm:^2.2.4, jquery@npm:~2.2.4":
+  version: 2.2.4
+  resolution: "jquery@npm:2.2.4"
+  checksum: 10/fe1bb90423eda61255b969fed0420dfb09dc055793b83ad380a2fbe5b5ce3bc747029d010e580bf39c95bdd07fb309ef8c0fc22a700ca97015311626881db152
+  languageName: node
+  linkType: hard
+
+"jquery@npm:~3.4.1":
+  version: 3.4.1
+  resolution: "jquery@npm:3.4.1"
+  checksum: 10/c40dcf94f6d1427b8d28b8f6b9d32f368b01e77cc24095c66c02de146faf0e633ef7c7f5d5815c52367b400f32d7c7f9c87e66d372488ffdd3276b4aeb6e0cef
+  languageName: node
+  linkType: hard
+
 "js-base64@npm:^2.1.9":
   version: 2.6.4
   resolution: "js-base64@npm:2.6.4"
@@ -11728,7 +11742,7 @@ __metadata:
     jasmine-jquery: "npm:~2.1.1"
     jest: "npm:~24.9.0"
     jest-cli: "npm:~24.9.0"
-    jquery: "npm:~3.7.1"
+    jquery: "npm:~2.2.4"
     jquery-ui: "npm:~1.13.2"
     jquery-ujs: "npm:~1.2.2"
     jquery.hotkeys: "npm:~0.1.0"


Reviews:
user: login: Fryguy
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-05-19T20:24:22Z
user: login: Fryguy
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-05-19T20:35:53Z

Review comments:
diff_hunk: @@ -5,8 +5,10 @@ enableGlobalCache: true
 nodeLinker: node-modules
 
 npmAuditExcludePackages:
-  - angular
-  - bootstrap
-  - bootstrap-sass
+- jquery
+# pending | moderate | GHSA-rmxg-73gg-4p98 | jquery >=1.12.3 <3.0.0 | 2.2.4 brought in by manageiq-ui-classic@workspace:.
+# pending | moderate | GHSA-gxr4-xjj5-5px2 | jquery >=1.2.0 <3.5.0  | 2.2.4, 3.4.1 brought in by manageiq-ui-classic@workspace:., patternfly@npm:3.59.5
+# pending | moderate | GHSA-6c3j-c64m-qhgq | jquery >=1.1.4 <3.4.0  | 2.2.4 brought in by manageiq-ui-classic@workspace:.
+# pending | moderate | GHSA-jpcq-cgw6-v4j6 | jquery >=1.0.3 <3.5.0  | 2.2.4, 3.4.1 brought in by manageiq-ui-classic@workspace:., patternfly@npm:3.59.5
path: .yarnrc.yml
user: login: Fryguy
body: Something weird happened with this revert. the angular and bootstrap entries need to stay.
created_at: 2025-05-19T20:24:22Z
author_association: MEMBER
diff_hunk: @@ -5,8 +5,10 @@ enableGlobalCache: true
 nodeLinker: node-modules
 
 npmAuditExcludePackages:
-  - angular
-  - bootstrap
-  - bootstrap-sass
+- jquery
+# pending | moderate | GHSA-rmxg-73gg-4p98 | jquery >=1.12.3 <3.0.0 | 2.2.4 brought in by manageiq-ui-classic@workspace:.
+# pending | moderate | GHSA-gxr4-xjj5-5px2 | jquery >=1.2.0 <3.5.0  | 2.2.4, 3.4.1 brought in by manageiq-ui-classic@workspace:., patternfly@npm:3.59.5
+# pending | moderate | GHSA-6c3j-c64m-qhgq | jquery >=1.1.4 <3.4.0  | 2.2.4 brought in by manageiq-ui-classic@workspace:.
+# pending | moderate | GHSA-jpcq-cgw6-v4j6 | jquery >=1.0.3 <3.5.0  | 2.2.4, 3.4.1 brought in by manageiq-ui-classic@workspace:., patternfly@npm:3.59.5
path: .yarnrc.yml
user: login: Fryguy
body: @jrafanie It's my fault - when I created the Yarn 4.9.1 PR (https://github.com/ManageIQ/manageiq-ui-classic/pull/9402), I accidentally removed the comments, which prevented the fix...let me get in a PR to undo that.
created_at: 2025-05-19T20:35:53Z
author_association: MEMBER

PR comments:
user: login: Fryguy
created_at: 2025-05-17T03:35:26Z
body: There's also the PR that removed jquery from the npm audit excludes
author_association: MEMBER
user: login: Fryguy
created_at: 2025-05-19T14:39:21Z
body: You also need to revert https://github.com/ManageIQ/manageiq-ui-classic/pull/9338
author_association: MEMBER
user: login: Fryguy
created_at: 2025-05-20T20:20:28Z
body: Backported to `spassky` in commit bc17f486d23f29f7405bacc7fb47ec0146454b87.

```text
commit bc17f486d23f29f7405bacc7fb47ec0146454b87
Author: Gilbert Cherrie <32444791+GilbertCherrie@users.noreply.github.com>
Date:   Tue May 20 15:56:55 2025 -0400

    Merge pull request #9438 from jrafanie/revert-jquery-371-upgrade
    
    Revert jquery 3.7.1 upgrade
    
    (cherry picked from commit 4dce1e6af35ace0a484f9b1fe98bcecdb5c5786e)
```

author_association: MEMBER