Skip to content

Commit a524d7f

Browse files
authored
Merge pull request #20 from davisjam/FixUndef
handle undefined string
2 parents 8585fac + b33cac4 commit a524d7f

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ var nonLocalhostDomainRE = /^[^\s\.]+\.\S{2,}$/;
2424
*/
2525

2626
function isUrl(string){
27+
if (typeof string !== 'string') {
28+
return false;
29+
}
30+
2731
var match = string.match(protocolAndDomainRE);
2832
if (!match) {
2933
return false;

test/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,22 @@ describe('is-url', function () {
118118
it('google.com', function () {
119119
assert(!url('google.com'));
120120
});
121+
122+
it('empty', function () {
123+
assert(!url(''));
124+
});
125+
126+
it('undef', function () {
127+
assert(!url(undefined));
128+
});
129+
130+
it('object', function () {
131+
assert(!url({}));
132+
});
133+
134+
it('re', function () {
135+
assert(!url(/abc/));
136+
});
121137
});
122138

123139
describe('redos', function () {

0 commit comments

Comments
 (0)