wei-spring / codenameone

Automatically exported from code.google.com/p/codenameone
0 stars 0 forks source link

String type is a problem in general with the new iOS VM - StringUtil.replaceAll() and backslash \ #1322

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Windows 7
iPhone4
Eclipse Kepler

StringUtil.replaceAll() does not work on Strings with \\ generated from a 
Stream. I consume json data from a web service.

protected void readResponse(InputStream input) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    Util.copy(input, bos);
    String s = bos.toString();
    s = StringUtil.replaceAll(s, "\\u0026", "&");

Similarly for json special characters:
"\\u0027", "'"
"\\u003c", "<"
"\\u003d", "="
"\\u003e", ">"

Anything characters appearing after double quote " (\\\") from json is 
truncated.

Works fine with the old iOS VM, android devices & the simulator.

When the string is built from code it works fine.
    String s = "This \\u0026 that.";
    s = StringUtil.replaceAll(s, "\\u0026", "&");

So backslash seems to be stored differently depending where it comes from.

Original issue reported on code.google.com by timun....@mattioli-woods.com on 29 Jan 2015 at 11:10

GoogleCodeExporter commented 9 years ago
The issue was actually in us using the \u internally to represent special 
characters and mistranslating that. So the stream got around fine but the 
hardcoded string was translated as & instead of as \u0026 so replace didn't 
work...
This should be fixed now, instead of using \u we are using ~~u as a shorthand 
internally which should see less conflict.

Original comment by shai.almog on 31 Jan 2015 at 10:58