[TIMOB-5878] Android: Titanium.UI.TextArea does not decode UTF8 character correctly.
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2012-04-18T10:38:45.000+0000 |
Affected Version/s | Release 1.7.3 |
Fix Version/s | Release 2.0.2, Release 2.1.0, Sprint 2012-08, Release 1.8.3 |
Components | Android |
Labels | api, module_textarea, parity, qe-manualtest |
Reporter | Qing Gao |
Assignee | Ping Wang |
Created | 2011-10-26T12:36:59.000+0000 |
Updated | 2014-08-07T22:28:41.000+0000 |
Description
TextArea does not decode UTF8 character correctly.
Repro Steps
Step 1: Open Kitchen Sink on Android Step 2: Go to Platform - XHR - UTF-8 + GET/POST Expected result: The string "€漢字" should be shown in the textarea. Actual result: Some garbage characters was shown.Workaround
In Javascript code, call the following decode function to decode what returns from HttpClient's responseText.
var myDecode = function (utftext) {
var string = "";
var i = 0;
var c = c1 = c2 = 0;
while ( i < utftext.length ) {
c = utftext.charCodeAt(i);
if (c < 128) {
string += String.fromCharCode(c);
i++;
}
else if((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i+1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
}
else {
c2 = utftext.charCodeAt(i+1);
c3 = utftext.charCodeAt(i+2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}
}
return string;
}
The sample fails because in Android, the function getResponseText() in TiHTTPClient.java uses charset=HTTP.DEFAULT_CONTENT_CHARSET which is "ISO-8859-1" as the default to encode responseData to a string when the http response doesn't specify a charset. The corresponding iOS code uses "UTF-8" as the default and the sample runs fine in iOS. The HTTP spec says using a default charset value of "ISO-8859-1" in http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7.1 . Need a parity discussion with iOS.
Uhm... any chances to get this resolved in, let's say, Mobile SDK 2.0? Would like to get rid of the decode function for Android.
Tested with 2.0.2.v20120505151714 with Samsung Nexus S 4.0.4