From fd5df4aefc20d9a7c61fdaee08f7943b5cc30433 Mon Sep 17 00:00:00 2001 From: Stamen Stoychev Date: Thu, 19 Nov 2026 17:13:27 +0200 Subject: [PATCH] fix(*): replace $.trim, which jQuery 4 removed #2302 jQuery 4 removed $.trim, so igDataSource, igHtmlEditor and the loader threw "$.trim is not a function", for example when binding the data source to a URL or filtering it locally. Add $.ig.util.trim, which behaves like $.trim on every jQuery version: null and undefined give "", other values are converted to a string and trimmed. Use it in the data source and the HTML editor. The loader runs before infragistics.util.js is loaded and only trims the strings it gets from split(","), so it calls String.prototype.trim directly. Co-Authored-By: Claude Opus 5.5 --- src/js/infragistics.loader.js | 6 +-- src/js/modules/infragistics.datasource.js | 28 +++++----- src/js/modules/infragistics.ui.htmleditor.js | 4 +- src/js/modules/infragistics.util.js | 6 +++ .../dataSource/filtering/filtering-test.js | 34 ++++++++++++ tests/unit/dataSource/remote/remote-test.js | 52 +++++++++++++++++++ .../rendering/htmleditor-test.js | 30 +++++++++++ tests/unit/loader/loader-test.js | 45 ++++++++++++++++ tests/unit/util/util-test.js | 23 ++++++++ 9 files changed, 209 insertions(+), 19 deletions(-) diff --git a/src/js/infragistics.loader.js b/src/js/infragistics.loader.js index 7e17344f9..45924fa17 100644 --- a/src/js/infragistics.loader.js +++ b/src/js/infragistics.loader.js @@ -2380,7 +2380,7 @@ $.extend($.ig.loaderClass, { this._loadBatches.push(loadBatch); for (i = 0; i < res.length; i++) { - (new $.ig._loadWorkItem(this)).loadWidgetResources($.trim(res[ i ]), loadBatch.callback); + (new $.ig._loadWorkItem(this)).loadWidgetResources(res[ i ].trim(), loadBatch.callback); } } return this; @@ -2524,7 +2524,7 @@ $.extend($.ig.loaderClass, { locales = this.settings.locale.split(","); localeScr = localeScripts.pop(); for ( k = 0; k < locales.length; k++) { - scriptData.unshift(localeScr.replace("$locale$", $.trim(locales[ k ]))); + scriptData.unshift(localeScr.replace("$locale$", locales[ k ].trim())); } } } @@ -2536,7 +2536,7 @@ $.extend($.ig.loaderClass, { while (regionalScripts.length > 0) { regionalScr = regionalScripts.pop(); for ( k = 0; k < regionals.length; k++) { - scriptData.unshift(regionalScr.replace("$regional$", $.trim(regionals[ k ]))); + scriptData.unshift(regionalScr.replace("$regional$", regionals[ k ].trim())); } } } diff --git a/src/js/modules/infragistics.datasource.js b/src/js/modules/infragistics.datasource.js index a5e98b190..2748010ac 100644 --- a/src/js/modules/infragistics.datasource.js +++ b/src/js/modules/infragistics.datasource.js @@ -2102,7 +2102,7 @@ return "invalid"; } if ($.ig.util.getType(ds) === "string") { //string or object - ds = $.trim(ds); + ds = $.ig.util.trim(ds); if (ds.startsWith("/")) { return "remoteUrl"; } @@ -4009,7 +4009,7 @@ // M.H. 9 Oct 2013 Fix for bug #139006: dataSourceType should be set explicitly when invoke dataBind with remote operations ds = this.dataSource(); if ($.ig.util.getType(ds) === "string") { //string or object - ds = $.trim(ds); + ds = $.ig.util.trim(ds); /* N.A. 02/10/2014 Bug #162293 Add support for https requests. */ if (ds.startsWith("/") || ds.startsWith("http://") || ds.startsWith("https://")) { this._runtimeType = "remoteUrl"; @@ -4497,7 +4497,7 @@ } } /* try to analyze and detect automatically */ - data = $.ig.util.getType(data) === "string" ? $.trim(data) : data; + data = $.ig.util.getType(data) === "string" ? $.ig.util.trim(data) : data; if ((data && $.ig.util.getType(data) === "string" && (data.startsWith("+)|(?=>+)|(?=<+)|(?=LIKE+)|(?=NOT\WLIKE)+|(?=>\=+)|(?=<\=+)/); - if ($.trim(exprs[ i ]).toLowerCase().startsWith("and")) { + tmp = $.ig.util.trim(exprs[ i ]).split(/(?= \=+)|(?=<>+)|(?=>+)|(?=<+)|(?=LIKE+)|(?=NOT\WLIKE)+|(?=>\=+)|(?=<\=+)/); + if ($.ig.util.trim(exprs[ i ]).toLowerCase().startsWith("and")) { fields[ i ].logic = "AND"; /* strip AND tmp[0] = tmp[0].substring(tmp.indexOf(3)); */ - } else if ($.trim(exprs[ i ]).toLowerCase().startsWith("or")) { + } else if ($.ig.util.trim(exprs[ i ]).toLowerCase().startsWith("or")) { fields[ i ].logic = "OR"; /* strip OR tmp[0] = tmp[0].substring(tmp.indexOf(2)); */ @@ -6229,11 +6229,11 @@ fields[ i - 1 ].logic = fields[ i ].logic; } if (tmp[ 0 ].toLowerCase().startsWith("and") || tmp[ 0 ].toLowerCase().startsWith("or")) { - fields[ i ].fieldName = $.trim(tmp[ 0 ].split(" ")[ 1 ]); + fields[ i ].fieldName = $.ig.util.trim(tmp[ 0 ].split(" ")[ 1 ]); } else { - fields[ i ].fieldName = $.trim(tmp[ 0 ]); + fields[ i ].fieldName = $.ig.util.trim(tmp[ 0 ]); } - tmp2 = $.trim(tmp[ 1 ]).split(" "); + tmp2 = $.ig.util.trim(tmp[ 1 ]).split(" "); /* fix ambiguous matching between <, >, and <> */ if (exprs[ i ].indexOf("<>") !== -1) { tmp2[ 0 ] = "<>"; @@ -6249,7 +6249,7 @@ tmp2 = [ tmp2[ 0 ], tmp2[ 1 ] ]; } if (tmp[ 1 ].startsWith("NOT")) { - fields[ i ].expr = $.trim(tmp[ 2 ].replace("LIKE", "")); + fields[ i ].expr = $.ig.util.trim(tmp[ 2 ].replace("LIKE", "")); } else { fields[ i ].expr = tmp2[ 1 ]; } @@ -6357,7 +6357,7 @@ return true; } - tmpExpr = $.trim(expr); + tmpExpr = $.ig.util.trim(expr); /*if (t === null || t === undefined) { t = $.ig.util.getType(expr); } */ @@ -8282,7 +8282,7 @@ text = ""; for (i = 0; i < li[ 0 ].childNodes.length; i++) { if (li[ 0 ].childNodes[ i ].nodeType === 3 && li[ 0 ].childNodes[ i ].data) { - text += $.trim(li[ 0 ].childNodes[ i ].data); + text += $.ig.util.trim(li[ 0 ].childNodes[ i ].data); } } diff --git a/src/js/modules/infragistics.ui.htmleditor.js b/src/js/modules/infragistics.ui.htmleditor.js index 397511076..a652a47da 100644 --- a/src/js/modules/infragistics.ui.htmleditor.js +++ b/src/js/modules/infragistics.ui.htmleditor.js @@ -1955,12 +1955,12 @@ // K.D. October 3rd, 2012 Bug #123366 Encoding the content before setting the value // D.A. November 4th, 2013 Bug #155847 Viewsource cannot be switched when there are leading whitespaces - this.sourceWindow.val($.trim(workSpaceBody.html())); + this.sourceWindow.val($.ig.util.trim(workSpaceBody.html())); workspace.hide(); this.sourceWindow.show(); } else { workSpaceBody.attr("contentEditable", true); - workSpaceBody.html($.trim(this.sourceWindow.val())); + workSpaceBody.html($.ig.util.trim(this.sourceWindow.val())); workspace.show(); this.sourceWindow.hide(); diff --git a/src/js/modules/infragistics.util.js b/src/js/modules/infragistics.util.js index c71472479..1ba4e9e1b 100644 --- a/src/js/modules/infragistics.util.js +++ b/src/js/modules/infragistics.util.js @@ -4437,6 +4437,12 @@ return str.replace(new RegExp($.ig.util.escapeRegExp(oldValue), "g"), newValue); }; + // Replaces $.trim, which jQuery 4 removed: null and undefined give "", + // other values are converted to a string and trimmed on both ends + $.ig.util.trim = function (value) { + return value == null ? "" : String(value).trim(); + }; + // Implements the .NET String.Format functionality $.ig.util.stringFormat = function (format) { return $.ig.util.stringFormat1(format, Array.prototype.slice.call(arguments, 1)); diff --git a/tests/unit/dataSource/filtering/filtering-test.js b/tests/unit/dataSource/filtering/filtering-test.js index cc9e9455e..8e5507ce8 100644 --- a/tests/unit/dataSource/filtering/filtering-test.js +++ b/tests/unit/dataSource/filtering/filtering-test.js @@ -1440,3 +1440,37 @@ QUnit.module("igDataSource filtering", { fd = ds.filteredData(); assert.ok(fd.length === 0, "The items shoould not be filtered"); }); + + QUnit.module("igDataSource filtering without $.trim (jQuery 4)", { + trim: null, + beforeEach: function () { + // jQuery 4 removed $.trim: https://github.com/IgniteUI/ignite-ui/issues/2302 + this.trim = $.trim; + delete $.trim; + }, + afterEach: function () { + $.trim = this.trim; + } + }); + + QUnit.test("Local filtering with field expressions", function (assert) { + assert.expect(1); + var ds = new $.ig.DataSource({ + dataSource: [{ ID: 1 }, { ID: 2 }, { ID: 3 }], + schema: { fields: [{ name: "ID", type: "number" }] } + }); + ds.dataBind(); + ds.filter([{ fieldName: "ID", expr: 2, cond: "greaterThan" }], "AND", true); + assert.deepEqual(ds.dataView(), [{ ID: 3 }], "Only the record with ID 3 should be left."); + }); + + QUnit.test("Local filtering with an expression string", function (assert) { + assert.expect(1); + var ds = new $.ig.DataSource({ + dataSource: [{ ID: 1 }, { ID: 2 }, { ID: 3 }], + schema: { fields: [{ name: "ID", type: "number" }] } + }); + ds.dataBind(); + ds.filter(" ID > 1 AND ID < 3 ", true); + assert.deepEqual(ds.dataView(), [{ ID: 2 }], "Only the record with ID 2 should be left."); + }); diff --git a/tests/unit/dataSource/remote/remote-test.js b/tests/unit/dataSource/remote/remote-test.js index 2cd78d933..4f2e37028 100644 --- a/tests/unit/dataSource/remote/remote-test.js +++ b/tests/unit/dataSource/remote/remote-test.js @@ -748,4 +748,56 @@ ds.settings.filtering.filterExprUrlKey = "filter"; params = $.param(ds._encodeUrl()); assert.equal(params, "filter(ProductID)=Contains(%25EF%25BC%2593)", "Filtering Expression Value should be escaped."); + }); + + QUnit.module("igDataSource Remote without $.trim (jQuery 4)", { + trim: null, + mockId: null, + beforeEach: function () { + // jQuery 4 removed $.trim: https://github.com/IgniteUI/ignite-ui/issues/2302 + this.trim = $.trim; + delete $.trim; + // A text response with surrounding whitespace, which the data source trims before parsing it + this.mockId = $.mockjax({ + url: "/trim-test/products", + contentType: "text/plain", + responseText: " { \"d\": { \"results\": [{ \"ID\": 1 }, { \"ID\": 2 }, { \"ID\": 3 }] } } " + }); + }, + afterEach: function () { + $.mockjax.clear(this.mockId); + $.trim = this.trim; + } + }); + + QUnit.test("Bind to a URL string", function (assert) { + assert.expect(3); + var done = assert.async(), ds; + ds = new $.ig.DataSource({ + dataSource: "/trim-test/products", + responseDataKey: "d.results", + callback: function (success, error) { + assert.ok(success, "The request should succeed. " + error); + assert.deepEqual(ds.dataView(), [{ ID: 1 }, { ID: 2 }, { ID: 3 }], "All records should be bound."); + done(); + } + }); + assert.equal(ds.analyzeDataSource(), "remoteUrl", "The data source should be recognized as a remote URL."); + ds.dataBind(); + }); + + QUnit.test("Bind to a URL string with type json", function (assert) { + assert.expect(2); + var done = assert.async(), ds; + ds = new $.ig.DataSource({ + type: "json", + dataSource: "/trim-test/products", + responseDataKey: "d.results", + callback: function (success, error) { + assert.ok(success, "The request should succeed. " + error); + assert.deepEqual(ds.dataView(), [{ ID: 1 }, { ID: 2 }, { ID: 3 }], "All records should be bound."); + done(); + } + }); + ds.dataBind(); }); \ No newline at end of file diff --git a/tests/unit/htmleditor/basicfunctionalities/rendering/htmleditor-test.js b/tests/unit/htmleditor/basicfunctionalities/rendering/htmleditor-test.js index 645dbbe9d..2c291bead 100644 --- a/tests/unit/htmleditor/basicfunctionalities/rendering/htmleditor-test.js +++ b/tests/unit/htmleditor/basicfunctionalities/rendering/htmleditor-test.js @@ -1790,3 +1790,33 @@ QUnit.test('[ID74] igHtmlEditor igToolbarHelper unit tests - Add image to editor }); }); +QUnit.module("igHTMLEditor without $.trim (jQuery 4)", { + trim: null, + beforeEach: function () { + // jQuery 4 removed $.trim: https://github.com/IgniteUI/ignite-ui/issues/2302 + this.trim = $.trim; + delete $.trim; + }, + afterEach: function () { + $.trim = this.trim; + } +}); + +QUnit.test("Switch to the source view and back", function (assert) { + assert.expect(4); + var htmlEditor = $.ig.TestUtil.appendToFixture('
', { id: "trimHtmlEditor" }).igHtmlEditor({}), + viewSourceBtn = htmlEditor.find(".ui-igbutton-viewsource"), + designView = $("#trimHtmlEditor_editor"), + sourceView = $("#trimHtmlEditor_source"); + + htmlEditor.igHtmlEditor("setContent", "

test

", "html"); + viewSourceBtn.click(); + assert.notOk(designView.is(":visible"), "The source view should be shown."); + assert.equal(sourceView.val(), "

test

", "The source view should contain the content."); + + sourceView.val("

changed

"); + viewSourceBtn.click(); + assert.ok(designView.is(":visible"), "The design view should be shown."); + assert.equal(htmlEditor.igHtmlEditor("getContent", "html"), "

changed

", "The edited source should be applied without the surrounding whitespace."); +}); + diff --git a/tests/unit/loader/loader-test.js b/tests/unit/loader/loader-test.js index 0b4983190..5f4e6ecd8 100644 --- a/tests/unit/loader/loader-test.js +++ b/tests/unit/loader/loader-test.js @@ -214,4 +214,49 @@ QUnit.test("test 4: Test load resources with multiple regionals", function (asse done(); } }); +}); + +QUnit.module("igLoader without $.trim (jQuery 4)", { + jsPath: "base/mock/src/js/", + cssPath: "base/mock/src/css/", + trim: null, + beforeEach: function () { + // jQuery 4 removed $.trim: https://github.com/IgniteUI/ignite-ui/issues/2302 + this.trim = $.trim; + delete $.trim; + }, + afterEach: function () { + $.trim = this.trim; + $("head > script[src*='" + this.jsPath + "'], head > link[href*='" + this.cssPath + "']").remove(); + } +}); + +QUnit.test("Load resources, locales and regionals from lists with spaces", function (assert) { + assert.expect(5); + var done = assert.async(), + expectedScripts = [ + "infragistics.templating.js", + "infragistics.templating-fr.js", + "infragistics.ui.editors.js", + "infragistics.ui.editors-fr.js", + "infragistics.ui.regional-fr.js" + ]; + + $.ig.loader({ + scriptPath: this.jsPath, + cssPath: this.cssPath, + resources: "igTemplating, igEditors", + locale: "en, fr", + regional: "en, fr", + ready: () => { + var loadedScripts = $("head > script[src*='" + this.jsPath + "']").map(function () { + return this.src.split("/").pop(); + }).get(); + + expectedScripts.forEach(function (script) { + assert.ok(loadedScripts.indexOf(script) !== -1, "The loaded resources should contain: " + script); + }); + done(); + } + }); }); \ No newline at end of file diff --git a/tests/unit/util/util-test.js b/tests/unit/util/util-test.js index 380405927..69c1b2350 100644 --- a/tests/unit/util/util-test.js +++ b/tests/unit/util/util-test.js @@ -432,4 +432,27 @@ QUnit.test('[ID21] Test String.concat', function (assert) { var arr = ["abc", "123"]; assert.equal(String.concat(arr[0], arr[1]), "abc123", "Default w/ Separate arguments"); assert.equal(String.concat(arr), "abc123", "Default w/ single argument"); +}); + +QUnit.test('[ID22] Test $.ig.util.trim', function (assert) { + assert.expect(14); + + var trim = $.trim, + values = [null, undefined, 0, 42, " ABC ", "\u00A0\uFEFF\t\r\n ABC \u00A0\uFEFF\t\r\n", "A B"], + expected = ["", "", "0", "42", "ABC", "ABC", "A B"], + i; + + for (i = 0; i < values.length; i++) { + assert.strictEqual($.ig.util.trim(values[i]), trim(values[i]), "Same result as $.trim for " + JSON.stringify(values[i])); + } + + // jQuery 4 removed $.trim: https://github.com/IgniteUI/ignite-ui/issues/2302 + delete $.trim; + try { + for (i = 0; i < values.length; i++) { + assert.strictEqual($.ig.util.trim(values[i]), expected[i], "Trimmed without $.trim: " + JSON.stringify(values[i])); + } + } finally { + $.trim = trim; + } }); \ No newline at end of file