Skip to content

Commit 3e7f432

Browse files
committed
Version jPskmail-3.1.8.1-20230826-Beta (unpublished)
- Bug fixes for handling of UTF-8 character set.
1 parent d714239 commit 3e7f432

4 files changed

Lines changed: 37 additions & 9 deletions

File tree

src/javapskmail/Arq.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,13 @@ public static String checksum(String intext) {
10371037
0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641,
10381038
0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040,};
10391039

1040-
byte[] bytes = intext.getBytes();
1040+
//byte[] bytes = intext.getBytes();
1041+
byte[] bytes;
1042+
try {
1043+
bytes = intext.getBytes("UTF-8");
1044+
} catch (java.io.UnsupportedEncodingException e) {
1045+
bytes = intext.getBytes();
1046+
}
10411047
int crc = 0x0000;
10421048
for (byte b : bytes) {
10431049
crc = (crc >>> 8) ^ table[(crc ^ b) & 0xff];

src/javapskmail/Main.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
public class Main {
3535

3636
//VK2ETA: Based on "jpskmail 1.7.b";
37-
static String version = "3.1.8";
37+
static String version = "3.1.8.1";
3838
static String application = "jPskmail " + version;// Used to preset an empty status
39-
static String versionDate = "20230825";
39+
static String versionDate = "20230826";
4040
static String host = "localhost";
4141
static int port = 7322; //ARQ IP port
4242
static String xmlPort = "7362"; //XML IP port
@@ -1100,7 +1100,7 @@ public static void main(String[] args) throws InterruptedException {
11001100
scall = cleanCallForAprs(scall);
11011101
if (scall.length() > 0) {
11021102
//Looks like a valid call sign
1103-
byte[] cmps = binfo.substring(0, 11).getBytes();
1103+
byte[] cmps = binfo.substring(0, 11).getBytes("UTF-8");
11041104
int flg = cmps[0] - 32;
11051105
int latdegrees = cmps[1] - 32;
11061106
String s_latdegrees = String.format("%02d", latdegrees);

src/javapskmail/RxBlock.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ private String analyze(String inString) throws IOException {
235235
BlockCRCwithPW = checksum(checkstring + Main.accessPassword);
236236
}
237237
if (BlockCRC.equals(crc)){
238-
valid =true;
238+
valid = true;
239239
}
240240
if (BlockCRCwithPW.equals(crc)) {
241241
validWithPW = true;
@@ -419,7 +419,13 @@ public String checksum(String intext) {
419419
};
420420

421421

422-
byte[] bytes = intext.getBytes();
422+
//byte[] bytes = intext.getBytes();
423+
byte[] bytes;
424+
try {
425+
bytes = intext.getBytes("UTF-8");
426+
} catch (java.io.UnsupportedEncodingException e) {
427+
bytes = intext.getBytes();
428+
}
423429
int crc1 = 0x0000;
424430
for (byte b : bytes) {
425431
crc1 = (crc1 >>> 8) ^ table[(crc1 ^ b) & 0xff];

src/javapskmail/Session.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2486,6 +2486,18 @@ public boolean TransactionsExists() {
24862486
public void SetBlocklength(int NewBlocklength) {
24872487
Blocklength = NewBlocklength;
24882488
}
2489+
2490+
//UTF strings handling
2491+
private int lengthCodepoints(String s) {
2492+
return s.codePointCount(0, s.length());
2493+
}
2494+
2495+
private static String substringCodepoint(String s, int startCodepoint, int numCodepoints) {
2496+
int startIndex = s.offsetByCodePoints(0, startCodepoint);
2497+
int endIndex = s.offsetByCodePoints(startIndex, numCodepoints);
2498+
return s.substring(startIndex, endIndex);
2499+
}
2500+
24892501

24902502
public String doTXbuffer() {
24912503

@@ -2556,15 +2568,19 @@ public String doTXbuffer() {
25562568
Blocklength = Maxblocklength;
25572569
}
25582570
double bl = Math.pow(2, Blocklength);
2559-
int queuelen = Main.txText.length();
2571+
//UTF-8 Handling. Use codepoints instead of raw string length
2572+
//int queuelen = Main.txText.length();
2573+
int queuelen = lengthCodepoints(Main.txText);
25602574

25612575
if (queuelen > 0) {
25622576
if (queuelen <= (int) bl) {
25632577
newstring = Main.txText;
25642578
Main.txText = "";
25652579
} else {
2566-
newstring = Main.txText.substring(0, (int) bl);
2567-
Main.txText = Main.txText.substring((int) bl);
2580+
//newstring = Main.txText.substring(0, (int) bl);
2581+
newstring = substringCodepoint(Main.txText, 0, (int) bl);
2582+
//Main.txText = Main.txText.substring((int) bl);
2583+
Main.txText = substringCodepoint(Main.txText, (int) bl, queuelen - (int) bl);
25682584
}
25692585

25702586
// lastqueued += 1;

0 commit comments

Comments
 (0)