Skip to content

Commit

Permalink
Merge pull request #1728 from igandrews/stringSplit
Browse files Browse the repository at this point in the history
Fixed stringSplit to escape the separators
  • Loading branch information
kdinev authored May 25, 2018
2 parents b6f0dae + 6637b1b commit e1f033a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/js/modules/infragistics.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5208,7 +5208,7 @@
r += "|";
}

r += separators[ i ];
r += $.ig.util.escapeRegExp(separators[ i ]);
}

var result = value.split(new RegExp(r));
Expand Down
73 changes: 73 additions & 0 deletions tests/unit/util/tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit e1f033a

Please sign in to comment.