Skip to content

Commit

Permalink
add support for protocol-less url
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jul 2, 2014
1 parent 5594626 commit a3c918d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = isUrl;
* Matcher.
*/

var matcher = /^\w+:\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/;
var matcher = /^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/;

/**
* Loosely validate a URL `string`.
Expand Down
4 changes: 4 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ describe('is-url', function () {
it('http://localhost:342/a/path', function () {
assert(url('http://localhost:342/a/path'));
});

it('//google.com', function () {
assert(url('//google.com'));
});
});

describe('invalid', function () {
Expand Down

1 comment on commit a3c918d

@dobon
Copy link

@dobon dobon commented on a3c918d Feb 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var matcher = /^(?:\w+:)?//([^\s.]+.\S{2}|localhost[:?\d])\S$/;

can be simplified to

var matcher = /^(\w+:)?//([^\s.]+.\S{2}|localhost[:?\d])\S$/;

(ie: the first "?:" doesn't do anything.) I would submit a PR for this, but I don't want to download the repo. hopefully this comment will spur action in a different way.

Please sign in to comment.