Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sanitize

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sanitize - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

37

lib/Sanitizer.js

@@ -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;
}

2

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc