Comparing version 0.0.5 to 0.0.6
@@ -77,3 +77,10 @@ /** | ||
url: function(value) { | ||
return vtor.isURL(value) ? value : null; | ||
var protocol; | ||
var options; | ||
if (_.isArray(value)) { | ||
protocol = value[1]; | ||
options = {protocols: [protocol]}; | ||
value = value[0]; | ||
} | ||
return vtor.isURL(value, options) ? fixUrl(value, protocol) : null; | ||
}, | ||
@@ -132,2 +139,28 @@ | ||
} | ||
}); | ||
}); | ||
function fixUrl(url, protocol) { | ||
if (!url) { | ||
return url; | ||
} | ||
protocol = protocol || 'http'; | ||
// does it start with desired protocol? | ||
if ((new RegExp('^' + protocol + ':\/\/', 'i')).test(url)) { | ||
return url; | ||
} | ||
// if we have a different protocol, then invalidate | ||
if (/^\w+:\/\//i.test(url)) { | ||
return null; | ||
} | ||
// apply protocol to "abc.com/abc" | ||
if (/^(?:\w+\.\w{2,})+(?:\/.*|$)/.test(url)) { | ||
return protocol + '://' + url; | ||
} | ||
return null; | ||
} |
{ | ||
"name": "sanitize", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Input sanitizing library for node.js", | ||
@@ -5,0 +5,0 @@ "main": "lib/sanitize.js", |
@@ -168,2 +168,22 @@ /** | ||
type: 'url', | ||
value: 'grooveshark.com/#!/search?q=funky+music', | ||
expected: 'http://grooveshark.com/#!/search?q=funky+music' | ||
}, | ||
{ | ||
type: 'url', | ||
value: ['grooveshark.com/#!/search?q=funky+music', 'sftp'], | ||
expected: 'sftp://grooveshark.com/#!/search?q=funky+music' | ||
}, | ||
{ | ||
type: 'url', | ||
value: ['sftp://grooveshark.com/#!/search?q=funky+music', 'sftp'], | ||
expected: 'sftp://grooveshark.com/#!/search?q=funky+music' | ||
}, | ||
{ | ||
type: 'url', | ||
value: ['http://grooveshark.com/#!/search?q=funky+music', 'sftp'], | ||
expected: null | ||
}, | ||
{ | ||
type: 'url', | ||
value: '', | ||
@@ -170,0 +190,0 @@ expected: null |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22835
735