Skip to content

Commit e2efe89

Browse files
Parameters with null characters fixed
1 parent 1321c29 commit e2efe89

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ tasks.withType<JavaCompile> {
2020
}
2121

2222
group = "com.github.pgasync"
23-
version = "1.0.4"
23+
version = "1.0.5"

src/main/java/com/github/pgasync/conversion/DataConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.pgasync.conversion;
22

3+
import com.github.pgasync.io.IO;
34
import com.pgasync.Converter;
45
import com.github.pgasync.Oid;
56

@@ -211,7 +212,7 @@ public byte[][] fromParameters(Object[] parameters) {
211212
int i = 0;
212213
for (Object param : parameters) {
213214
String converted = fromObject(param);
214-
params[i++] = converted == null ? null : converted.getBytes(encoding);
215+
params[i++] = converted == null ? null : IO.removeNulls(converted).getBytes(encoding);
215216
}
216217
return params;
217218
}

src/main/java/com/github/pgasync/io/IO.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
public class IO {
2727

28-
private static final String NULL = String.valueOf('\u0000');
28+
public static final String NULL = String.valueOf('\u0000');
2929

3030
public static String getCString(ByteBuffer buffer, Charset charset) {
3131
ByteArrayOutputStream readBuffer = new ByteArrayOutputStream(255);
@@ -37,9 +37,13 @@ public static String getCString(ByteBuffer buffer, Charset charset) {
3737

3838
public static void putCString(ByteBuffer buffer, String value, Charset charset) {
3939
if (!value.isEmpty()) {
40-
buffer.put(value.replace(NULL, "").getBytes(charset));
40+
buffer.put(removeNulls(value).getBytes(charset));
4141
}
4242
buffer.put((byte) 0);
4343
}
4444

45+
public static String removeNulls(String value) {
46+
return value.replace(NULL, "");
47+
}
48+
4549
}

0 commit comments

Comments
 (0)