Skip to content

Commit

Permalink
fix charEncode when all string are empty or null
Browse files Browse the repository at this point in the history
  • Loading branch information
pmarziotto-midinero committed Oct 19, 2021
1 parent 259592d commit bfb8a35
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions jpos/src/main/java/org/jpos/iso/ISOUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -1665,7 +1665,8 @@ public static String charEncode (char delimiter, String... ss) {
StringBuilder sb = new StringBuilder();
for (int j = 0, ssLength = ss.length; j < ssLength; j++) {
String s = ss[j];
if (s == null || s.length() == 0) {
final boolean notLast = j < ssLength - 1;
if (notLast && (s == null || s.length() == 0)) {
sb.append(delimiter);
continue;
}
Expand All @@ -1676,7 +1677,7 @@ public static String charEncode (char delimiter, String... ss) {
}
sb.append(c);
}
if (j < ssLength - 1) {
if (notLast) {
sb.append(delimiter);
}
}
Expand Down
2 changes: 2 additions & 0 deletions jpos/src/test/java/org/jpos/iso/ISOUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5183,12 +5183,14 @@ public void testStringDLE() {
@Test
public void testCharEncodeAndDecode() {
assertEquals("", ISOUtil.charEncode(':'), "error encoding \"\"");
assertEquals(":", ISOUtil.charEncode(':', "",""), "error encoding \"\",\"\"");
assertEquals("a:b:c", ISOUtil.charEncode(':', "a", "b", "c"), "error encoding \"a:b:c\"");
assertEquals("\\::\\\\:c", ISOUtil.charEncode(':', ":", "\\", "c"), "error encoding \"\\::\\\\:c\"");
assertEquals(":b:c", ISOUtil.charEncode(':', "", "b", "c"), "error encoding \":b:c\"");
assertEquals("::b:c", ISOUtil.charEncode(':', "", "", "b", "c"), "error encoding \"::b:c\"");

assertArrayEquals(new String[] {""}, ISOUtil.charDecode(':',""), "error decoding \"\"");
assertArrayEquals(new String[] {"", ""}, ISOUtil.charDecode(':',":"), "error decoding \":\"");
assertArrayEquals(new String[] { "a", "b", "c" }, ISOUtil.charDecode(':', "a:b:c"), "error decoding \"a:b:c\"");
assertArrayEquals(new String[] { ":", "\\", "c" }, ISOUtil.charDecode(':', "\\::\\\\:c"), "error decoding \"\\::\\\\:c\"");
assertArrayEquals(new String[] { "", "b", "c" }, ISOUtil.charDecode(':', ":b:c"), "error decoding \":b:c\"");
Expand Down

0 comments on commit bfb8a35

Please sign in to comment.