Skip to content

Commit

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

Solution:
Revert to pre-segmentio#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 24, 2018
1 parent f1c83cf commit c32a7d3
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 c32a7d3

Please sign in to comment.