Skip to content

Commit

Permalink
handle undefined string
Browse files Browse the repository at this point in the history
Problem:
As reported in #19, PR #18 changed behavior on:
- undefined string
- non-strings

Solution:
Revert to pre-#18 behavior on non-strings: return false.

Test:
I added test cases to clarify this behavior.
It shouldn't happen again.
  • Loading branch information
davisjam committed Mar 26, 2018
1 parent 8585fac commit b33cac4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
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
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 b33cac4

Please sign in to comment.