Skip to content

Commit

Permalink
Merge pull request #2223 from igandrews/TFS274456_Main
Browse files Browse the repository at this point in the history
Handle single array argument for param array member in string.concat
  • Loading branch information
hanastasov authored Feb 13, 2023
2 parents e3fe59b + 3b7e249 commit f097dd7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/js/modules/infragistics.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3836,36 +3836,32 @@
return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, "").replace(/\s+/g, " ");
};

String.prototype.trimStart = function () {
var getParamsArray = function(a) {
var args = [ " " ];
if (arguments.length > 0) {
if (arguments.length == 1 && Array.isArray(arguments[ 0 ])) {
if (arguments[ 0 ].length > 0) {
args = arguments[ 0 ];
if (a && a.length > 0) {
if (a.length == 1 && Array.isArray(a[ 0 ])) {
if (a[ 0 ].length > 0) {
args = a[ 0 ];
}
} else {
args = Array.prototype.slice.call(arguments);
args = Array.prototype.slice.call(a);
}
}

return args;
};
String.prototype.trimStart = function () {
if (this.length === 0) {
return this;
}
var args = getParamsArray(arguments);
var i = 0;
for (; i < this.length && args.indexOf(this.charAt(i)) > -1; i++) { }
return this.substring(i);
};

String.prototype.trimEnd = function () {
var args = [ " " ];
if (arguments.length > 0) {
if (arguments.length == 1 && Array.isArray(arguments[ 0 ])) {
if (arguments[ 0 ].length > 0) {
args = arguments[ 0 ];
}
} else {
args = Array.prototype.slice.call(arguments);
}
}
var args = getParamsArray(arguments);
var i = this.length - 1;
for (; i >= 0 && args.indexOf(this.charAt(i)) > -1; i--) { }
return this.substring(0, i + 1);
Expand All @@ -3875,7 +3871,7 @@
String.isNullOrEmpty = function (s) { return !s || s.length < 1; };
String.isNullOrWhiteSpace = function (s) { return !s || s.trim().length < 1; };
String.empty = function () { return ""; };
String.concat = function () { return [ ].join.call(arguments, ""); };
String.concat = function () { return [ ].join.call(getParamsArray(arguments), ""); };
String.concat1 = function (o1, o2) { return [ ].join.call(arguments, ""); };
String.concat2 = function (s1, s2) { return [ ].join.call(arguments, ""); };
String.concat3 = function () { return [ ].join.call(arguments, ""); };
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/util/util-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,4 +424,12 @@ QUnit.test('[ID20] Test OADate', function (assert) {
var d1 = new Date(1999, 6, 4, 12, 0, 0);
assert.equal(d1.toOADate(), 36345.5, "toOADate for " + d1);
assert.equal($.ig.Date.prototype.fromOADate(36345.5).getTime(), +d1, "fromOADate to " + d1);
});

QUnit.test('[ID21] Test String.concat', function (assert) {
assert.expect(2);

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");
});

0 comments on commit f097dd7

Please sign in to comment.