Skip to content

Commit

Permalink
Merge pull request #196 from eakron/master
Browse files Browse the repository at this point in the history
fixing `URI(undefined)` to throw TypeError
  • Loading branch information
rodneyrehm committed Mar 11, 2015
2 parents 962f222 + 35dd050 commit b9b5635
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/URI.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
}

if (url === undefined) {
if (arguments.length) {
throw new TypeError('undefined is not a valid argument for URI');
}

if (typeof location !== 'undefined') {
url = location.href + '';
} else {
Expand Down
7 changes: 6 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@
new URI(new Date());
}, TypeError, 'Failing unknown input');
});
test('new URI(undefined)', function() {
raises(function() {
new URI(undefined);
}, TypeError, 'Failing undefined input');
});
test('new URI()', function() {
var u = new URI();
ok(u instanceof URI, 'instanceof URI');
Expand Down Expand Up @@ -1589,4 +1594,4 @@
equal(URI.encodeReserved('ä:/?#[]@!$&\'()*+,;='), '%C3%A4:/?#[]@!$&\'()*+,;=');
});

})();
})();

0 comments on commit b9b5635

Please sign in to comment.