Skip to content

Commit

Permalink
Clarify URL validation error on invalid http url
Browse files Browse the repository at this point in the history
  • Loading branch information
James Buchan committed Jul 28, 2015
1 parent ae3d6bf commit 131994c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/valve.js
Expand Up @@ -804,9 +804,12 @@ Chain.prototype.isHttpUrl = function() {
this._pushValidator({
name: 'isUrl',
func: function(value, baton, callback) {
if (!check.isURL(value, { protocols: ['http', 'https'], require_protocol: true })) {
if (!check.isURL(value)) {
callback('Invalid URL');
return;
} else if (!check.isURL(value, { protocols: ['http', 'https'], require_protocol: true })) {
callback('Invalid URL. URL must begin with http:// or https://.');
return;
}
callback(null, value);
},
Expand Down
4 changes: 2 additions & 2 deletions tests/test-valve.js
Expand Up @@ -434,13 +434,13 @@ exports['test_validate_http_url'] = function(test, assert) {
// ftp test
var ftp_url = { a: 'ftp://rackspace.com' };
v.check(ftp_url, function(err, cleaned) {
assert.deepEqual(err.message, 'Invalid URL', 'HTTP URL test with FTP URL');
assert.deepEqual(err.message, 'Invalid URL. URL must begin with http:// or https://.', 'HTTP URL test with FTP URL');
});

// no protocol test
var no_proto = { a: 'rackspace.com' };
v.check(no_proto, function(err, cleaned) {
assert.deepEqual(err.message, 'Invalid URL', 'HTTP URL test with no protocol specified');
assert.deepEqual(err.message, 'Invalid URL. URL must begin with http:// or https://.', 'HTTP URL test with no protocol specified');
});

// negative case
Expand Down

0 comments on commit 131994c

Please sign in to comment.