Skip to content

Commit

Permalink
Merge pull request #20 from davisjam/FixUndef
Browse files Browse the repository at this point in the history
handle undefined string
  • Loading branch information
zeke authored Mar 26, 2018
2 parents 8585fac + b33cac4 commit a524d7f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ var nonLocalhostDomainRE = /^[^\s\.]+\.\S{2,}$/;
*/

function isUrl(string){
if (typeof string !== 'string') {
return false;
}

var match = string.match(protocolAndDomainRE);
if (!match) {
return false;
Expand Down
16 changes: 16 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ describe('is-url', function () {
it('google.com', function () {
assert(!url('google.com'));
});

it('empty', function () {
assert(!url(''));
});

it('undef', function () {
assert(!url(undefined));
});

it('object', function () {
assert(!url({}));
});

it('re', function () {
assert(!url(/abc/));
});
});

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

0 comments on commit a524d7f

Please sign in to comment.