Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-6835] iOS: Network - createHttpClient cannot handle Japanese Shift_JIS and EUC-JP encoding

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-02-21T16:44:36.000+0000
Affected Version/sRelease 1.7.3
Fix Version/sSprint 2012-04, Release 2.0.0
ComponentsiOS
Labelsmodule_network, parity, qe-testadded
ReporterSatoshi Tanaka
AssigneeNeeraj Gupta
Created2011-10-26T05:13:09.000+0000
Updated2014-06-19T12:43:15.000+0000

Description

Problem

Most of Japanese webpages use utf-8 encoding, but some pages use old encodings (Shift-JIS or EUC-JP). charset list (as reference) http://www.iana.org/assignments/character-sets But a return value will be set to null if Japanese webpage is acquired using Titanium.Network.createHttpClient.

Test case

I make a sample code which accesses each charset sample webpage and display their results.
var win1 = Ti.UI.createWindow({
	backgroundColor: 'white',
});
var text = Ti.UI.createLabel({
	text: '',
});
win1.add(text);
win1.open();
charsetTest("http://kangaechu.com/utf8.html");
charsetTest("http://kangaechu.com/shiftjis.html");
charsetTest("http://kangaechu.com/eucjp.html");

function charsetTest(url){
	var xhr = Ti.Network.createHTTPClient();
	
	xhr.onload = function() {
		if(this.status == 200) {
			var html = this.responseText;
			if(html == null){
				text.text = text.text + url + ' is null.\n\n';
			}
			else if(html.match(/<body>([\s\S]*)<\/body>/)){
				var body = RegExp.$1;
				text.text = text.text + url + body;
			}else{
				text.text = text.text + url + ' is 200, but no body element.\n\n';
			}
		}else{
			text.text = text.text + url + ' status code is ' + this.status + '\n\n';
		}
	};
	xhr.onerror = function() {
		text.text = text.text + url + ' status code is ' + this.status + '\n\n';

	};
	xhr.open("GET", url, false);
	xhr.send();
	
}
result is below: ||OS || UTF-8 || Shift_JIS || EUC-JP || |iOS | OK | null | null|

Suggested Fix

To fix this bug, add charset list to TiNetworkHTTPClientProxy.m See https://github.com/appcelerator/titanium_mobile/pull/590

Comments

  1. Wilson Luu 2012-03-14

    Closing bug. Verified fix on: SDK build: 2.0.0.v20120314154741 Titanium Studio, build: 2.0.0.201203132050 xcode: 4.2 Device: iphone 4s (5.0.1)

JSON Source