Character mangling when string is passed from "Java" to javascript through JSNI

50 views
Skip to first unread message

monkeyboy

unread,
May 3, 2012, 4:16:29 AM5/3/12
to google-we...@googlegroups.com
Consider the following code:

for (char c = 0; c < 0xFFFF; c++) { printStr("" + c, (int) c); } private native void printStr(String str, int c) /*-{ if (str.charCodeAt(0) != c) { console.log("c:" + c + ", code:" + str.charCodeAt(0)); } }-*/;
A simple loop that calls a simple javascript method through JSNI. In my opinion the method should not print anything to the browser's console. Alas it prints all the characters with code 55296 - 57343. The code that it prints is always 63.
I have filed an issue here:http://code.google.com/p/google-web-toolkit/issues/detail?id=7350. What would be the best way to avoid this problem?

Thomas Broyer

unread,
May 3, 2012, 4:45:17 AM5/3/12
to google-we...@googlegroups.com
Well, never try to use unpaired surrogates?
(see my comment on the issue for more context) 
Reply all
Reply to author
Forward
0 new messages