Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes NACChannel setHeader to use hex2byte. Fixes #510 #537

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
agustiza marked this conversation as resolved.
Show resolved Hide resolved
}
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));
}
}