From 58eb35f820977b71cab038b95c1ab11c6a65a468 Mon Sep 17 00:00:00 2001 From: Agustin Izaguirre Date: Mon, 8 May 2023 23:04:37 -0300 Subject: [PATCH] Changes NACChannel setHeader to use hex2byte. Fixes #510 --- jpos/src/main/java/org/jpos/iso/ISOUtil.java | 2 +- .../java/org/jpos/iso/channel/NACChannel.java | 2 +- .../java/org/jpos/iso/channel/NACChannelTest.java | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) 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..09f1fd46c1 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, null)); //fixes #jPOS-510 } 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)); + } }