Skip to content

Commit

Permalink
Changes NACChannel setHeader to use hex2byte. Fixes jpos#510
Browse files Browse the repository at this point in the history
  • Loading branch information
agustiza committed May 9, 2023
1 parent 80ed139 commit 782b170
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion jpos/src/main/java/org/jpos/iso/ISOUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion jpos/src/main/java/org/jpos/iso/channel/NACChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)); //fixes #jPOS-510
}
public void setConfiguration (Configuration cfg)
throws ConfigurationException
Expand Down
15 changes: 15 additions & 0 deletions jpos/src/test/java/org/jpos/iso/channel/NACChannelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}

0 comments on commit 782b170

Please sign in to comment.