Socket
Socket
Sign inDemoInstall

valid-url

Package Overview
Dependencies
0
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.5 to 1.0.6

28

index.js

@@ -51,22 +51,14 @@ (function(module) {

// scheme and path are required, though the path can be empty
if (!(scheme && scheme.length && path)) {
return;
}
if (!(scheme && scheme.length && path.length >= 0)) return;
// if authority is present, the path must be empty or begin with a /
if (authority && authority.length) {
if (!(path.length || /^\//.test(path))) {
return;
}
if (!(path.length === 0 || /^\//.test(path))) return;
} else {
// if authority is not present, the path must not start with //
if (/^\/\//.test(path)) {
return;
}
if (/^\/\//.test(path)) return;
}
// scheme must begin with a letter, then consist of letters, digits, +, ., or -
if (!/^[a-z][a-z0-9\+\-\.]*$/.test(scheme.toLowerCase())) {
return;
}
if (!/^[a-z][a-z0-9\+\-\.]*$/.test(scheme.toLowerCase())) return;

@@ -114,10 +106,8 @@ // re-assemble the URL per section 5.3 in RFC 3986

if (!scheme) {
return;
}
if (!scheme) return;
if (scheme.toLowerCase() !== 'http') {
if (!(allowHttps && scheme.toLowerCase() === 'https')) {
return;
}
if(allowHttps) {
if (scheme.toLowerCase() != 'https') return;
} else {
if (scheme.toLowerCase() != 'http') return;
}

@@ -124,0 +114,0 @@

@@ -11,3 +11,3 @@ {

],
"version": "1.0.5",
"version": "1.0.6",
"repository": {

@@ -23,6 +23,4 @@ "url": "git://github.com/ogt/valid-url.git"

"tap": "~0.4.3",
"jshint": "~2.1.4",
"assert": "*",
"vows": "*"
"jshint": "~2.1.4"
}
}

@@ -1,51 +0,22 @@

(function() {
'use strict';
var assert = require('assert'),
vows = require('vows'),
validUrl = require('../');
var test = require("tap").test,
is_http_uri = require('../').is_http_uri;
vows.describe('valid-url').addBatch({
'HTTP full url checking': {
topic: validUrl.is_http_uri('http://test:testPasswd@testdomain.com:8081/test?test=test#123'),
'result should be valid': function (result) {
assert.isString(result);
assert.equal(result, 'http://test:testPasswd@testdomain.com:8081/test?test=test#123');
}
},
'HTTP url-params checking': {
topic: validUrl.is_http_uri('http://test:testPasswd@testdomain.com:8081/test?test=test'),
'result should be valid': function (result) {
assert.isString(result);
assert.equal(result, 'http://test:testPasswd@testdomain.com:8081/test?test=test');
}
},
'HTTP url checking': {
topic: validUrl.is_http_uri('http://test:testPasswd@testdomain.com:8081/test'),
'result should be valid': function (result) {
assert.isString(result);
assert.equal(result, 'http://test:testPasswd@testdomain.com:8081/test');
}
},
'HTTP default port checking': {
topic: validUrl.is_http_uri('http://test:testPasswd@testdomain.com/test?test=test#123'),
'result should be valid': function (result) {
assert.isString(result);
assert.equal(result, 'http://test:testPasswd@testdomain.com/test?test=test#123');
}
},
'HTTP anonymous checking': {
topic: validUrl.is_http_uri('http://testdomain.com:8081/test?test=test#123'),
'result should be valid': function (result) {
assert.isString(result);
assert.equal(result, 'http://testdomain.com:8081/test?test=test#123');
}
},
'HTTPS allow checking': {
topic: validUrl.is_http_uri('https://test:testPasswd@testdomain.com:8081/test?test=test#123', true),
'result should be valid': function (result) {
assert.isString(result);
assert.equal(result, 'https://test:testPasswd@testdomain.com:8081/test?test=test#123');
}
}
}).export(module);
})(module);
test("testing is_http_uri", function (t) {
// valid
t.ok(is_http_uri('http://www.richardsonnen.com/'), 'http://www.richardsonnen.com/');
t.ok(is_http_uri('http://www.richardsonnen.com'), 'http://www.richardsonnen.com');
t.ok(is_http_uri('http://www.richardsonnen.com/foo/bar/test.html'), 'http://www.richardsonnen.com/foo/bar/test.html');
t.ok(is_http_uri('http://www.richardsonnen.com/?foo=bar'), 'http://www.richardsonnen.com/?foo=bar');
t.ok(is_http_uri('http://www.richardsonnen.com:8080/test.html'), 'http://www.richardsonnen.com:8080/test.html');
t.ok(is_http_uri('http://example.w3.org/path%20with%20spaces.html'), 'http://example.w3.org/path%20with%20spaces.html');
t.ok(is_http_uri('http://192.168.0.1/'), 'http://192.168.0.1/');
// invalid
t.notOk(is_http_uri(''), "bad: ''");
t.notOk(is_http_uri('ftp://ftp.richardsonnen.com'), "bad: 'ftp://ftp.richardsonnen.com'");
t.notOk(is_http_uri('http:www.richardsonnen.com'), "bad: 'http:www.richardsonnen.com'");
t.notOk(is_http_uri('https://www.richardsonnen.com'), "bad: 'https://www.richardsonnen.com'");
t.end();
});

@@ -1,44 +0,22 @@

(function() {
'use strict';
var assert = require('assert'),
vows = require('vows'),
validUrl = require('../');
var test = require("tap").test,
is_https_uri = require('../').is_https_uri;
vows.describe('valid-url').addBatch({
'HTTPS full url checking': {
topic: validUrl.is_https_uri('https://test:testPasswd@testdomain.com:8081/test?test=test#123'),
'result should be valid': function (result) {
assert.isString(result);
assert.equal(result, 'https://test:testPasswd@testdomain.com:8081/test?test=test#123');
}
},
'HTTPS url-params checking': {
topic: validUrl.is_https_uri('https://test:testPasswd@testdomain.com:8081/test?test=test'),
'result should be valid': function (result) {
assert.isString(result);
assert.equal(result, 'https://test:testPasswd@testdomain.com:8081/test?test=test');
}
},
'HTTPS url checking': {
topic: validUrl.is_https_uri('https://test:testPasswd@testdomain.com:8081/test'),
'result should be valid': function (result) {
assert.isString(result);
assert.equal(result, 'https://test:testPasswd@testdomain.com:8081/test');
}
},
'HTTPS default port checking': {
topic: validUrl.is_https_uri('https://test:testPasswd@testdomain.com/test?test=test#123'),
'result should be valid': function (result) {
assert.isString(result);
assert.equal(result, 'https://test:testPasswd@testdomain.com/test?test=test#123');
}
},
'HTTPS anonymous checking': {
topic: validUrl.is_https_uri('https://testdomain.com:8081/test?test=test#123'),
'result should be valid': function (result) {
assert.isString(result);
assert.equal(result, 'https://testdomain.com:8081/test?test=test#123');
}
}
}).export(module);
})(module);
test("testing is_https_uri", function (t) {
// valid
t.ok(is_https_uri('https://www.richardsonnen.com/'), 'https://www.richardsonnen.com/');
t.ok(is_https_uri('https://www.richardsonnen.com'), 'https://www.richardsonnen.com');
t.ok(is_https_uri('https://www.richardsonnen.com/foo/bar/test.html'), 'https://www.richardsonnen.com/foo/bar/test.html');
t.ok(is_https_uri('https://www.richardsonnen.com/?foo=bar'), 'https://www.richardsonnen.com/?foo=bar');
t.ok(is_https_uri('https://www.richardsonnen.com:8080/test.html'), 'https://www.richardsonnen.com:8080/test.html');
t.ok(is_https_uri('https://example.w3.org/path%20with%20spaces.html'), 'http://example.w3.org/path%20with%20spaces.html');
t.ok(is_https_uri('https://192.168.0.1/'), 'http://192.168.0.1/');
// invalid
t.notOk(is_https_uri(''), "bad: ''");
t.notOk(is_https_uri('http://www.richardsonnen.com/'), 'http://www.richardsonnen.com/');
t.notOk(is_https_uri('ftp://ftp.richardsonnen.com'), "bad: 'ftp://ftp.richardsonnen.com'");
t.notOk(is_https_uri('https:www.richardsonnen.com'), "bad: 'https:www.richardsonnen.com'");
t.end();
});

@@ -22,15 +22,15 @@ var test = require("tap").test,

// invalid
t.ok(!is_uri(''), "bad: ''");
t.ok(!is_uri('foo'), 'bad: foo');
t.ok(!is_uri('foo@bar'), 'bad: foo@bar');
t.ok(!is_uri('http://<foo>'), 'bad: http://<foo>'); // illegal characters
t.ok(!is_uri('://bob/'), 'bad: ://bob/'); // empty schema
t.ok(!is_uri('1http://bob'), 'bad: 1http://bob/'); // bad schema
t.ok(!is_uri('1http:////foo.html'), 'bad: 1http://bob/'); // bad path
t.ok(!is_uri('http://example.w3.org/%illegal.html'), 'http://example.w3.org/%illegal.html');
t.ok(!is_uri('http://example.w3.org/%a'), 'http://example.w3.org/%a'); // partial escape
t.ok(!is_uri('http://example.w3.org/%a/foo'), 'http://example.w3.org/%a/foo'); // partial escape
t.ok(!is_uri('http://example.w3.org/%at'), 'http://example.w3.org/%at'); // partial escape
t.notOk(is_uri(''), "bad: ''");
t.notOk(is_uri('foo'), 'bad: foo');
t.notOk(is_uri('foo@bar'), 'bad: foo@bar');
t.notOk(is_uri('http://<foo>'), 'bad: http://<foo>'); // illegal characters
t.notOk(is_uri('://bob/'), 'bad: ://bob/'); // empty schema
t.notOk(is_uri('1http://bob'), 'bad: 1http://bob/'); // bad schema
t.notOk(is_uri('1http:////foo.html'), 'bad: 1http://bob/'); // bad path
t.notOk(is_uri('http://example.w3.org/%illegal.html'), 'http://example.w3.org/%illegal.html');
t.notOk(is_uri('http://example.w3.org/%a'), 'http://example.w3.org/%a'); // partial escape
t.notOk(is_uri('http://example.w3.org/%a/foo'), 'http://example.w3.org/%a/foo'); // partial escape
t.notOk(is_uri('http://example.w3.org/%at'), 'http://example.w3.org/%at'); // partial escape
t.end();
});

@@ -1,51 +0,28 @@

(function() {
'use strict';
var assert = require('assert'),
vows = require('vows'),
validUrl = require('../');
var test = require("tap").test,
is_web_uri = require('../').is_web_uri;
vows.describe('valid-url').addBatch({
'Web full url checking': {
topic: validUrl.is_web_uri('http://test:testPasswd@testdomain.com:8081/test?test=test#123'),
'result should be valid': function (result) {
assert.isString(result);
assert.equal(result, 'http://test:testPasswd@testdomain.com:8081/test?test=test#123');
}
},
'Web url-params checking': {
topic: validUrl.is_web_uri('http://test:testPasswd@testdomain.com:8081/test?test=test'),
'result should be valid': function (result) {
assert.isString(result);
assert.equal(result, 'http://test:testPasswd@testdomain.com:8081/test?test=test');
}
},
'Web url checking': {
topic: validUrl.is_web_uri('http://test:testPasswd@testdomain.com:8081/test'),
'result should be valid': function (result) {
assert.isString(result);
assert.equal(result, 'http://test:testPasswd@testdomain.com:8081/test');
}
},
'Web default port checking': {
topic: validUrl.is_web_uri('http://test:testPasswd@testdomain.com/test?test=test#123'),
'result should be valid': function (result) {
assert.isString(result);
assert.equal(result, 'http://test:testPasswd@testdomain.com/test?test=test#123');
}
},
'Web anonymous checking': {
topic: validUrl.is_web_uri('http://testdomain.com:8081/test?test=test#123'),
'result should be valid': function (result) {
assert.isString(result);
assert.equal(result, 'http://testdomain.com:8081/test?test=test#123');
}
},
'Web https allow checking': {
topic: validUrl.is_web_uri('https://test:testPasswd@testdomain.com:8081/test?test=test#123', true),
'result should be valid': function (result) {
assert.isString(result);
assert.equal(result, 'https://test:testPasswd@testdomain.com:8081/test?test=test#123');
}
}
}).export(module);
})(module);
test("testing is_web_uri", function (t) {
// valid
t.ok(is_web_uri('https://www.richardsonnen.com/'), 'https://www.richardsonnen.com/');
t.ok(is_web_uri('https://www.richardsonnen.com'), 'https://www.richardsonnen.com');
t.ok(is_web_uri('https://www.richardsonnen.com/foo/bar/test.html'), 'https://www.richardsonnen.com/foo/bar/test.html');
t.ok(is_web_uri('https://www.richardsonnen.com/?foo=bar'), 'https://www.richardsonnen.com/?foo=bar');
t.ok(is_web_uri('https://www.richardsonnen.com:8080/test.html'), 'https://www.richardsonnen.com:8080/test.html');
t.ok(is_web_uri('http://www.richardsonnen.com/'), 'http://www.richardsonnen.com/');
t.ok(is_web_uri('http://www.richardsonnen.com'), 'http://www.richardsonnen.com');
t.ok(is_web_uri('http://www.richardsonnen.com/foo/bar/test.html'), 'http://www.richardsonnen.com/foo/bar/test.html');
t.ok(is_web_uri('http://www.richardsonnen.com/?foo=bar'), 'http://www.richardsonnen.com/?foo=bar');
t.ok(is_web_uri('http://www.richardsonnen.com:8080/test.html'), 'http://www.richardsonnen.com:8080/test.html');
t.ok(is_web_uri('http://example.w3.org/path%20with%20spaces.html'), 'http://example.w3.org/path%20with%20spaces.html');
t.ok(is_web_uri('http://192.168.0.1/'), 'http://192.168.0.1/');
// invalid
t.ok(!is_web_uri(''), "bad: ''");
t.ok(!is_web_uri('ftp://ftp.richardsonnen.com'), "bad: 'ftp://ftp.richardsonnen.com'");
t.ok(!is_web_uri('https:www.richardsonnen.com'), "bad: 'http:www.richardsonnen.com'");
t.ok(!is_web_uri('http:www.richardsonnen.com'), "bad: 'http:www.richardsonnen.com'");
t.end();
});
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc