diff --git a/jpos/src/main/java/org/jpos/iso/ISOUtil.java b/jpos/src/main/java/org/jpos/iso/ISOUtil.java index d92f9264c7..6ed891322b 100644 --- a/jpos/src/main/java/org/jpos/iso/ISOUtil.java +++ b/jpos/src/main/java/org/jpos/iso/ISOUtil.java @@ -299,7 +299,7 @@ public static String bcd2str(byte[] b, int offset, return d.toString(); } /** - * converts a a byte array to a String with padding support + * converts a byte array to a String with padding support * @param b - HEX representation * @param offset - starting offset * @param len - BCD field len diff --git a/jpos/src/main/java/org/jpos/iso/channel/NACChannel.java b/jpos/src/main/java/org/jpos/iso/channel/NACChannel.java index 9d9ffd50d0..a345b3ff35 100644 --- a/jpos/src/main/java/org/jpos/iso/channel/NACChannel.java +++ b/jpos/src/main/java/org/jpos/iso/channel/NACChannel.java @@ -114,7 +114,7 @@ protected void sendMessageHeader(ISOMsg m, int len) throws IOException { * @param header String as seen by QSP */ public void setHeader (String header) { - super.setHeader (ISOUtil.str2bcd(header, false)); + super.setHeader(ISOUtil.hex2byte(header)); } public void setConfiguration (Configuration cfg) throws ConfigurationException diff --git a/jpos/src/test/java/org/jpos/iso/channel/NACChannelTest.java b/jpos/src/test/java/org/jpos/iso/channel/NACChannelTest.java index ff4a9aad28..233f24c22c 100644 --- a/jpos/src/test/java/org/jpos/iso/channel/NACChannelTest.java +++ b/jpos/src/test/java/org/jpos/iso/channel/NACChannelTest.java @@ -27,9 +27,11 @@ import static org.junit.jupiter.api.Assertions.fail; import java.net.ServerSocket; +import java.nio.charset.StandardCharsets; import org.jpos.iso.ISOMsg; import org.jpos.iso.ISOPackager; +import org.jpos.iso.ISOUtil; import org.jpos.iso.filter.DelayFilter; import org.jpos.iso.packager.CTCSubFieldPackager; import org.jpos.iso.packager.ISO93APackager; @@ -236,4 +238,17 @@ public void testSetHeaderThrowsNullPointerException() throws Throwable { assertSame(TPDU2, nACChannel.getHeader(), "nACChannel.getHeader()"); } } + + @Test + void testSetHeaderDoesNotMangleOnNonHexCharacters() { + //jPOS-510 + String expectedTpdu = "A4M09000"; + String hex = ISOUtil.hexString(expectedTpdu.getBytes()); //"41344D3039303030" + + NACChannel channel = new NACChannel(); + channel.setHeader(hex); + + byte[] header = channel.getHeader(); + assertEquals(expectedTpdu, new String(header, StandardCharsets.UTF_8)); + } }