Skip to content

Commit

Permalink
fix(constructor): prevent null values from blowing up - #321
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingcheung authored and rodneyrehm committed Dec 15, 2016
1 parent b2ff01d commit 09fd3b5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

The release notes tracked in this document are also made available on the [releases page](https://github.com/medialize/URI.js/releases)

### master

* prevent `new URI(null)` from blowing up - [PR #321](https://github.com/medialize/URI.js/issues/321)

### 1.18.4 (December 4th 2016) ###

* fixing [`URI.withinString()`](http://medialize.github.io/URI.js/docs.html#static-withinString) to capture balanced parentheses - [Issue #247](https://github.com/medialize/URI.js/issues/247)
Expand Down
6 changes: 6 additions & 0 deletions src/URI.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
}
}

if (url === null) {
if (_urlSupplied) {
throw new TypeError('null is not a valid argument for URI');
}
}

this.href(url);

// resolve to base according to http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#constructor
Expand Down
5 changes: 5 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
URI(undefined);
}, TypeError, 'Failing undefined input');
});
test('URI(null)', function() {
raises(function() {
URI(null);
}, TypeError, 'Failing undefined input');
});
test('new URI(string)', function() {
var u = new URI('http://example.org/');
ok(u instanceof URI, 'instanceof URI');
Expand Down

0 comments on commit 09fd3b5

Please sign in to comment.