Fix url parser crash when url is not set

master
Letícia Camara 2018-10-13 02:04:46 -03:00
parent 5839fc515f
commit cb8f0ba3fd
1 changed files with 2 additions and 0 deletions

View File

@ -7,10 +7,12 @@ function addProtocol(url, protocol) {
}
function stripProtocol(url){
if(!url) return '';
return url.replace(/(^\w+:|^)\/\//, '');
}
function getProtocol(url){
if(!url) return '';
const values = url.match(/(^\w+:|^)\/\//);
return values && (values.length > 0) ? values[0] : '';