diff --git a/src/js/modules/infragistics.util.js b/src/js/modules/infragistics.util.js index d696af3c2..bf37af82a 100644 --- a/src/js/modules/infragistics.util.js +++ b/src/js/modules/infragistics.util.js @@ -5208,7 +5208,7 @@ r += "|"; } - r += separators[ i ]; + r += $.ig.util.escapeRegExp(separators[ i ]); } var result = value.split(new RegExp(r)); diff --git a/tests/unit/util/tests.html b/tests/unit/util/tests.html index 800248af9..980ad94a5 100644 --- a/tests/unit/util/tests.html +++ b/tests/unit/util/tests.html @@ -219,6 +219,79 @@ equal($.ig.util.stringCompare2("", null, c, o), 1, "empty after null"); }); + test("Test stringSplit", function () { + equal($.ig.util.stringSplit('', [','], $.ig.StringSplitOptions.prototype.none).toString(), '', 'Empty String - Single Separator - None'); + equal($.ig.util.stringSplit('', [','], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), '', 'Empty String - Single Separator - RemoveEmptyEntries'); + equal($.ig.util.stringSplit('abcd', [','], $.ig.StringSplitOptions.prototype.none).toString(), 'abcd', 'Plain String w/o Separators - Single Separator - None'); + equal($.ig.util.stringSplit('abcd', [','], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), 'abcd', 'Plain String w/o Separators - Single Separator - RemoveEmptyEntries'); + equal($.ig.util.stringSplit('ab,cd', [','], $.ig.StringSplitOptions.prototype.none).toString(), 'ab,cd', 'String w/ One Separator - Single Separator - None'); + equal($.ig.util.stringSplit('ab,cd', [','], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), 'ab,cd', 'String w/ One Separator - Single Separator - RemoveEmptyEntries'); + equal($.ig.util.stringSplit('ab,,cd', [','], $.ig.StringSplitOptions.prototype.none).toString(), 'ab,,cd', 'String w/ Adjacent Separators - Single Separator - None'); + equal($.ig.util.stringSplit('ab,,cd', [','], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), 'ab,cd', 'String w/ Adjacent Separators - Single Separator - RemoveEmptyEntries'); + equal($.ig.util.stringSplit(',abcd', [','], $.ig.StringSplitOptions.prototype.none).toString(), ',abcd', 'String w/ Leading Separator - Single Separator - None'); + equal($.ig.util.stringSplit(',abcd', [','], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), 'abcd', 'String w/ Leading Separator - Single Separator - RemoveEmptyEntries'); + equal($.ig.util.stringSplit('abcd,', [','], $.ig.StringSplitOptions.prototype.none).toString(), 'abcd,', 'String w/ Trailing Separator - Single Separator - None'); + equal($.ig.util.stringSplit('abcd,', [','], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), 'abcd', 'String w/ Trailing Separator - Single Separator - RemoveEmptyEntries'); + equal($.ig.util.stringSplit(',', [','], $.ig.StringSplitOptions.prototype.none).toString(), ',', 'Only Separators1 - Single Separator - None'); + equal($.ig.util.stringSplit(',', [','], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), '', 'Only Separators1 - Single Separator - RemoveEmptyEntries'); + equal($.ig.util.stringSplit(',,', [','], $.ig.StringSplitOptions.prototype.none).toString(), ',,', 'Only Separators2 - Single Separator - None'); + equal($.ig.util.stringSplit(',,', [','], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), '', 'Only Separators2 - Single Separator - RemoveEmptyEntries'); + equal($.ig.util.stringSplit(',ab,,c,d', [','], $.ig.StringSplitOptions.prototype.none).toString(), ',ab,,c,d', 'String w/ Lots of Separators - Single Separator - None'); + equal($.ig.util.stringSplit(',ab,,c,d', [','], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), 'ab,c,d', 'String w/ Lots of Separators - Single Separator - RemoveEmptyEntries'); + equal($.ig.util.stringSplit('abcd', [',', ';'], $.ig.StringSplitOptions.prototype.none).toString(), 'abcd', 'Plain String w/o Separators - Multiple Separators - None'); + equal($.ig.util.stringSplit('abcd', [',', ';'], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), 'abcd', 'Plain String w/o Separators - Multiple Separators - RemoveEmptyEntries'); + equal($.ig.util.stringSplit('a,bc,d', [',', ';'], $.ig.StringSplitOptions.prototype.none).toString(), 'a,bc,d', 'Plain String w Separator1 - Multiple Separators - None'); + equal($.ig.util.stringSplit('a,bc,d', [',', ';'], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), 'a,bc,d', 'Plain String w Separator1 - Multiple Separators - RemoveEmptyEntries'); + equal($.ig.util.stringSplit('a;bc;d', [',', ';'], $.ig.StringSplitOptions.prototype.none).toString(), 'a,bc,d', 'Plain String w Separator2 - Multiple Separators - None'); + equal($.ig.util.stringSplit('a;bc;d', [',', ';'], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), 'a,bc,d', 'Plain String w Separator2 - Multiple Separators - RemoveEmptyEntries'); + equal($.ig.util.stringSplit('a;bc,d', [',', ';'], $.ig.StringSplitOptions.prototype.none).toString(), 'a,bc,d', 'Plain String w Both Separators - Multiple Separators - None'); + equal($.ig.util.stringSplit('a;bc,d', [',', ';'], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), 'a,bc,d', 'Plain String w Both Separators - Multiple Separators - RemoveEmptyEntries'); + equal($.ig.util.stringSplit(';', [',', ';'], $.ig.StringSplitOptions.prototype.none).toString(), ',', 'Only Separators1 - Multiple Separator - None'); + equal($.ig.util.stringSplit(';', [',', ';'], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), '', 'Only Separators1 - Multiple Separator - RemoveEmptyEntries'); + equal($.ig.util.stringSplit(',;', [',', ';'], $.ig.StringSplitOptions.prototype.none).toString(), ',,', 'Only Separators2 - Multiple Separator - None'); + equal($.ig.util.stringSplit(',;', [',', ';'], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), '', 'Only Separators2 - Multiple Separator - RemoveEmptyEntries'); + equal($.ig.util.stringSplit(';,', [',', ';'], $.ig.StringSplitOptions.prototype.none).toString(), ',,', 'Only Separators3 - Multiple Separator - None'); + equal($.ig.util.stringSplit(';,', [',', ';'], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), '', 'Only Separators3 - Multiple Separator - RemoveEmptyEntries'); + equal($.ig.util.stringSplit(',', [',', ';'], $.ig.StringSplitOptions.prototype.none).toString(), ',', 'Only Separators4 - Multiple Separator - None'); + equal($.ig.util.stringSplit(',', [',', ';'], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), '', 'Only Separators4 - Multiple Separator - RemoveEmptyEntries'); + equal($.ig.util.stringSplit(';,;,,', [',', ';'], $.ig.StringSplitOptions.prototype.none).toString(), ',,,,,', 'Only Separators5 - Multiple Separator - None'); + equal($.ig.util.stringSplit(';,;,,', [',', ';'], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), '', 'Only Separators5 - Multiple Separator - RemoveEmptyEntries'); + equal($.ig.util.stringSplit('abcd', [';3'], $.ig.StringSplitOptions.prototype.none).toString(), 'abcd', 'Plain String w/o Separators - MultiChar Separator - None'); + equal($.ig.util.stringSplit('abcd', [';3'], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), 'abcd', 'Plain String w/o Separators - MultiChar Separator - RemoveEmptyEntries'); + equal($.ig.util.stringSplit('ab,cd', [';3'], $.ig.StringSplitOptions.prototype.none).toString(), 'ab,cd', 'String w/ One Separator - MultiChar Separator - None'); + equal($.ig.util.stringSplit('ab,cd', [';3'], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), 'ab,cd', 'String w/ One Separator - MultiChar Separator - RemoveEmptyEntries'); + equal($.ig.util.stringSplit('ab,,cd', [';3'], $.ig.StringSplitOptions.prototype.none).toString(), 'ab,,cd', 'String w/ Adjacent Separators - MultiChar Separator - None'); + equal($.ig.util.stringSplit('ab,,cd', [';3'], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), 'ab,,cd', 'String w/ Adjacent Separators - MultiChar Separator - RemoveEmptyEntries'); + equal($.ig.util.stringSplit(',abcd', [';3'], $.ig.StringSplitOptions.prototype.none).toString(), ',abcd', 'String w/ Leading Separator - MultiChar Separator - None'); + equal($.ig.util.stringSplit(',abcd', [';3'], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), ',abcd', 'String w/ Leading Separator - MultiChar Separator - RemoveEmptyEntries'); + equal($.ig.util.stringSplit('abcd,', [';3'], $.ig.StringSplitOptions.prototype.none).toString(), 'abcd,', 'String w/ Trailing Separator - MultiChar Separator - None'); + equal($.ig.util.stringSplit('abcd,', [';3'], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), 'abcd,', 'String w/ Trailing Separator - MultiChar Separator - RemoveEmptyEntries'); + equal($.ig.util.stringSplit(',ab,,c,d', [';3'], $.ig.StringSplitOptions.prototype.none).toString(), ',ab,,c,d', 'String w/ Lots of Separators - MultiChar Separator - None'); + equal($.ig.util.stringSplit(',ab,,c,d', [';3'], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), ',ab,,c,d', 'String w/ Lots of Separators - MultiChar Separator - RemoveEmptyEntries'); + equal($.ig.util.stringSplit(';3', [';3'], $.ig.StringSplitOptions.prototype.none).toString(), ',', 'Only Separators1 - MultiChar Separator - None'); + equal($.ig.util.stringSplit(';3', [';3'], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), '', 'Only Separators1 - MultiChar Separator - RemoveEmptyEntries'); + equal($.ig.util.stringSplit(';3;3', [';3'], $.ig.StringSplitOptions.prototype.none).toString(), ',,', 'Only Separators2 - MultiChar Separator - None'); + equal($.ig.util.stringSplit(';3;3', [';3'], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), '', 'Only Separators2 - MultiChar Separator - RemoveEmptyEntries'); + equal($.ig.util.stringSplit('3;33;;;333', [';3'], $.ig.StringSplitOptions.prototype.none).toString(), '3,3;;,33', 'Parts Of MultiChar Separator w/ Separators - MultiChar Separator - None'); + equal($.ig.util.stringSplit('3;33;;;333', [';3'], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), '3,3;;,33', 'Parts Of MultiChar Separator w/ Separators - MultiChar Separator - RemoveEmptyEntries'); + equal($.ig.util.stringSplit('5|25|abc', ['|'], $.ig.StringSplitOptions.prototype.none).toString(), '5,25,abc', 'Pipe Separator - None'); + equal($.ig.util.stringSplit('5|25|abc', ['|'], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), '5,25,abc', 'Pipe Separator - RemoveEmptyEntries'); + equal($.ig.util.stringSplit('5.25', ['.'], $.ig.StringSplitOptions.prototype.none).toString(), '5,25', 'Period Separator1 - None'); + equal($.ig.util.stringSplit('5.25', ['.'], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), '5,25', 'Period Separator1 - RemoveEmptyEntries'); + equal($.ig.util.stringSplit('5.252.568,35', ['.'], $.ig.StringSplitOptions.prototype.none).toString(), '5,252,568,35', 'Period Separator2 - None'); + equal($.ig.util.stringSplit('5.252.568,35', ['.'], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), '5,252,568,35', 'Period Separator2 - RemoveEmptyEntries'); + equal($.ig.util.stringSplit('.5.252..568,35..', ['.'], $.ig.StringSplitOptions.prototype.none).toString(), ',5,252,,568,35,,', 'Period Separator3 - None'); + equal($.ig.util.stringSplit('.5.252..568,35..', ['.'], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), '5,252,568,35', 'Period Separator3 - RemoveEmptyEntries'); + equal($.ig.util.stringSplit('5,45.3|35;3', ['.', ' ', '|3'], $.ig.StringSplitOptions.prototype.none).toString(), '5,45,3,5;3', 'Other Examples 1 - None'); + equal($.ig.util.stringSplit('5,45.3|35;3', ['.', ' ', '|3'], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), '5,45,3,5;3', 'Other Examples 1 - RemoveEmptyEntries'); + equal($.ig.util.stringSplit(' some white space around words', [' '], $.ig.StringSplitOptions.prototype.none).toString(), ',some,white,space,around,words', 'Other Examples 2 - None'); + equal($.ig.util.stringSplit(' some white space around words', [' '], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), 'some,white,space,around,words', 'Other Examples 2 - RemoveEmptyEntries'); + equal($.ig.util.stringSplit('abc 123 xyz', [' '], $.ig.StringSplitOptions.prototype.none).toString(), 'abc,123,xyz', 'Other Examples 3 - None'); + equal($.ig.util.stringSplit('abc 123 xyz', [' '], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), 'abc,123,xyz', 'Other Examples 3 - RemoveEmptyEntries'); + equal($.ig.util.stringSplit('This is easy. So is this.', ['.', ' ', '!', '>'], $.ig.StringSplitOptions.prototype.none).toString(), 'This,is,easy,,So,is,this,', 'Other Examples 4 - None'); + equal($.ig.util.stringSplit('This is easy. So is this.', ['.', ' ', '!', '>'], $.ig.StringSplitOptions.prototype.removeEmptyEntries).toString(), 'This,is,easy,So,is,this', 'Other Examples 4 - RemoveEmptyEntries'); + }); + test("Test trimStart", function () { equal(" ABC ".trimStart(), "ABC ", "No arguments"); equal(" ABC ".trimStart([]), "ABC ", "Empty array argument");