Skip to content

Commit 03bc11d

Browse files
Fix internalization bug in message deserialization for case when JVM file encoding is not UTF-8 or ISO-8859-1
1 parent 2af3445 commit 03bc11d

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎java/src1/com/pubnub/api/HttpClientCore.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private static String readInput(InputStream in) throws IOException {
7676
n = in.read(bytes);
7777
}
7878

79-
return new String(out.toString());
79+
return new String(out.toString("utf8"));
8080
}
8181

8282
public HttpResponse fetch(String url) throws PubnubException, SocketTimeoutException {

‎java/srcTest/com/pubnub/api/PubnubTest.java‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,32 @@ public void connectCallback(String channel, Object message) {
231231
assertEquals(sendMessage, sbCb.getResponse());
232232
}
233233

234+
/**
235+
* It is need to run JVM with option -Dfile.encoding=windows-1251(or something else latin incompatible encoding) in order to reproduce issue which covered by this test
236+
*/
237+
@Test
238+
public void testPublishNonLatinString() throws PubnubException, InterruptedException {
239+
String channel = "java-unittest-" + Math.random();
240+
final String sendMessage = "\u0440\u0443\u0441\u0441\u043a\u0438\u0439 " + Math.random();
241+
242+
final CountDownLatch latch = new CountDownLatch(2);
243+
244+
final PublishCallback pbCb = new PublishCallback(latch);
245+
SubscribeCallback sbCb = new SubscribeCallback(latch) {
246+
@Override
247+
public void connectCallback(String channel, Object message) {
248+
pubnub.publish(channel, sendMessage, pbCb);
249+
}
250+
};
251+
252+
pubnub.subscribe(channel, sbCb);
253+
254+
latch.await(10, TimeUnit.SECONDS);
255+
256+
assertEquals(1, pbCb.getResult());
257+
assertEquals(sendMessage, sbCb.getResponse());
258+
}
259+
234260
@Test
235261
public void testPublishJSONArray() throws PubnubException, InterruptedException {
236262
String channel = "java-unittest-" + Math.random();

0 commit comments

Comments
 (0)