Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-6387] iOS: The Webview's "error" event is not handled properly and cause crash.

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-03-14T13:25:13.000+0000
Affected Version/sRelease 1.7.5, Release 1.8.0, Release 1.8.0.1
Fix Version/sSprint 2011-48, Release 1.7.6, Release 1.8.0.1
ComponentsiOS
Labelsmerge-1.7.6, module_webview, qe-testadded
ReporterQing Gao
AssigneeSabil Rahim
Created2011-11-30T12:25:55.000+0000
Updated2016-01-15T10:16:43.000+0000

Description

The "error" event is not handled properly in WebView and crash the app.

Repro Steps

Step 1. Create a project based on the following code. Step 2. Input "www.yahoo.com," and return. The webview will open up it correctly Step 3. Input some random word and hit enter. the app would crash.
var win = Ti.UI.createWindow({ backgroundColor: '#fff' });

var input = Ti.UI.createTextArea({
	top:40,
	height:60,
	borderColor:'#333',
	borderRadius: 10,
	autocapitalization:Titanium.UI.TEXT_AUTOCAPITALIZATION_NONE
});

function makeweb(url2){
	var web = Ti.UI.createWebView({
		html:null,
		url:url2
	});
	var window = Titanium.UI.createWindow({});
	
	//
	//
	// Attaching the 'error' event listener results in a crash on poorly formed URLS
	//
	//
	web.addEventListener('error', function(e) {
		alert('error');
	});
	
	window.add(web);
	return window;
};

win.add(input);

input.addEventListener('return', function(e) {
	var link = input.value.toString();
	web = makeweb('http://'+link);
	web.open();
});
win.addEventListener('open', function() {
	input.focus();
});

win.open();

Attachments

FileDateSize
testLinkCrash_2011-11-30-094839_qgaombp.crash2011-11-30T12:25:55.000+000040881

Comments

  1. Michael Pettiford 2011-12-05

    Tested on Ti Studio 1.0.7.201112041107 Ti Mob SDK 1.8.0.1.v20111205011857 OSX Lion iPod Touch 4.3.5, iPhone 4S OS 5.0.1, iPad 2 OS 4.3.5 Expected behavior shown of proper error handling with a invalid url
  2. Natalie Huynh 2012-01-04

    Open to add label
  3. Dustin Hyde 2012-03-13

    Bug still exists under certain conditions: - Invalid characters such as: % and : (ascii 37 and 58). - Spaces in the url. SDK: 1.8.2 githash=59b3a90s, 2.0.0.v20120312213243 Studio: 2.0.0.201203121914 OS: Snow Leopard Devices Tested: iPod 4.3.3, iOS Simulator 5.0 Crash does not occur on Android. Steps to Reproduce: 1. Run code below.
       var win = Ti.UI.createWindow({
       	backgroundColor:'blue',
       	top:0,
       	layout:'vertical'
       	});
       	
       var asciiButton = Ti.UI.createButton({
       	title:'ascii char url test',
       	top:0,
       	width:'100%',
       	height:'20%'
       });
       
       asciiButton.addEventListener('click', function(){
       	var webView = Ti.UI.createWebView();
       	
       	win.add(webView);
       	
       	var asciiCount = 1024;
       	
       	for(var i = 0; i < asciiCount; i++)
       	{		
       		var string = String.fromCharCode(i);
       		
       		Ti.API.info(i + ': ' + string);
       		
       		webView.url = string;
       	}
       	
       	win.remove(webView);
       });
       
       win.add(asciiButton);
       
       var intButton = Ti.UI.createButton({
       	title:'int url test',
       	width:'100%',
       	top:0,
       	height:'20%'
       });
       
       intButton.addEventListener('click', function(){
       	var webView = Ti.UI.createWebView();
       	
       	win.add(webView);
       	
       	var intCount = 2500;
       	
       	for(var i = 0; i < intCount; i++)
       	{
       		var string = i.toString();
       		
       		Ti.API.info(i + ': ' + string);
       		
       		webView.url = string;
       	}
       	
       	win.remove(webView);
       });
       
       win.add(intButton);
       
       var floatButton = Ti.UI.createButton({
       	title:'float url test',
       	width:'100%',
       	top:0,
       	height:'20%'
       });
       
       floatButton.addEventListener('click', function(){
       	var webView = Ti.UI.createWebView();
       	
       	win.add(webView);
       	
       	var floatCount = 10.0;
       	
       	for(var i = 0.0; i < floatCount; i += 0.01)
       	{
       		var string = i.toString();
       		
       		Ti.API.info(i + ': ' + string);
       		
       		webView.url = string;
       	}
       	
       	win.remove(webView);
       });
       
       win.add(floatButton);
       
       var objectButton = Ti.UI.createButton({
       	title:'object url test',
       	width:'100%',
       	top:0,
       	height:'20%'
       });
       
       objectButton.addEventListener('click', function(){
       	var webView = Ti.UI.createWebView();
       	
       	win.add(webView);
       	
       	var objectList = [
       		true,
       		{},
       		[],
       		1,
       		0.9,
       		null,
       		undefined
       	];
       	
       	for(var i in objectList)
       	{
       		var object = objectList[i];
       		
       		Ti.API.info(i + ': ' + object);
       		
       		try
       		{
       			webView.url = object;
       		}
       		catch(e)
       		{
       			Ti.API.info(e.toString());
       		}
       	}
       	
       	win.remove(webView);
       });
       
       win.add(objectButton);
       
       var urlStringButton = Ti.UI.createButton({
       	title:'url string url test',
       	width:'100%',
       	top:0,
       	height:'20%'
       });
       
       urlStringButton.addEventListener('click', function(){
       	var webView = Ti.UI.createWebView();
       	
       	win.add(webView);
       	
       	var urlList = [
       		'www.yahoo.com',
       		'www.notarealwebsiteatall.com',
       		's p a c e s'
       	];
       	
       	for(var i in urlList)
       	{
       		var url = 'http://';
       		
       		url += urlList[i];
       		
       		Ti.API.info(i + ': ' + url);
       		
       		webView.url = url;
       	}
       	
       	win.remove(webView);
       });
       
       win.add(urlStringButton);
       
       win.open();
       
    2. Click 'ascii char url test' or 'url string url test'. Expected Result: App should not crash. Actual Result: App crashes.
  4. Dustin Hyde 2012-03-14

  5. jithinpv 2013-11-25

    Anvil test case added. PR link: https://github.com/appcelerator/titanium_mobile/pull/5020

JSON Source