Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-5878] Android: Titanium.UI.TextArea does not decode UTF8 character correctly.

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2012-04-18T10:38:45.000+0000
Affected Version/sRelease 1.7.3
Fix Version/sRelease 2.0.2, Release 2.1.0, Sprint 2012-08, Release 1.8.3
ComponentsAndroid
Labelsapi, module_textarea, parity, qe-manualtest
ReporterQing Gao
AssigneePing Wang
Created2011-10-26T12:36:59.000+0000
Updated2014-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;
}

Associated Helpdesk Ticket

http://appc.me/c/APP-589719

Comments

  1. Ping Wang 2011-10-31

    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.
  2. MAIRDUMONT GmbH & Co. KG 2012-03-26

    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.
  3. Natalie Huynh 2012-05-07

    Tested with 2.0.2.v20120505151714 with Samsung Nexus S 4.0.4

JSON Source