Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-6835

iOS: Network - createHttpClient cannot handle Japanese Shift_JIS and EUC-JP encoding

    Details

    • Type: Bug
    • Status: Closed
    • Priority: High
    • Resolution: Fixed
    • Affects Version/s: Release 1.7.3
    • Fix Version/s: Sprint 2012-04, Release 2.0.0
    • Component/s: iOS
    • Environment:

      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.

      app.js

      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

        Attachments

          Activity

            People

            • Assignee:
              ngupta Neeraj Gupta
              Reporter:
              kangae2 Satoshi Tanaka
            • Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Git Source Code