Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19162] HTTPClient - request url with leading blanks cause an exception

GitHub Issuen/a
TypeBug
PriorityNone
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
Labels3.4.0, 3.4.1, TCSupportTriage, exception, httpclient, iOS8, url
ReporterMarkus Eschenbach
AssigneeUnknown
Created2014-11-10T11:18:08.000+0000
Updated2018-02-28T19:55:32.000+0000

Description

Problem description

When the httpclient request url starts with leading blanks, an exception is thrown when the "send()" function is executed. {noformat} message = "-[NSNull rangeOfString:]: unrecognized selector sent to instance 0x3a804690"; {noformat}

Steps to reproduce

Create HTTPClient and use a request url with leading blanks: " http://www.appcelerator.com"

Test case

(function() {
	
	var urls = [
		"http://www.appcelerator.com",
		"www.appcelerator.com",
		"appcelerator.com",
		"http://www.appcelerator2.com",
		"http2://www.appcelerator.com",
		"http:www.appcelerator.com",
		"   http://www.appcelerator.com" //exception
	];	
	var win = Ti.UI.createWindow({backgroundColor:'#ffffff'});
	var view = Ti.UI.createView({layout:'vertical'});
	var button = Ti.UI.createButton({title:' Run test ',top:100,borderRadius:5,borderColor:'#1C1C1C',backgroundColor:'#C0C0C0'});
	var output = Ti.UI.createLabel({top: 20,font:{fontSize:11}});
	
	button.addEventListener('click',function(){
		output.text = '';
		for (var i=0; i < urls.length; i++) {
		  sendGET(i,urls[i]);
		}		
	});
	
	view.add(button);
	view.add(output);
	win.add(view);
	
	function sendGET(i,url){
		
		var client = Ti.Network.createHTTPClient({
		     onload : function(e) {
		     	 var msg = 'Test ' + i + ': ' + url + ' - success';
		     	 output.text += '\n' + msg;
		         Ti.API.log(msg);
		     },
		     onerror : function(e) {
		     	var msg = 'Test ' + i + ': ' + url + ' - error';
		     	output.text += '\n' + msg;
		     	Ti.API.error(msg);
		     },
		});
	 	client.open("GET", url);
	 	try{
			client.send();
		}catch(e){
	     	var msg = 'Test ' + i + ': ' + url + ' - EXCEPTION';
	     	output.text += '\n' + msg;
	     	Ti.API.error(msg);			
		}		
	}

	win.open();
})();

Comments

No comments

JSON Source