Skip to content

Commit

Permalink
Fixing Issue #6 - Error thrown on .query(true) if query was null
Browse files Browse the repository at this point in the history
  • Loading branch information
rodneyrehm committed Dec 30, 2011
1 parent af4ef57 commit 1a691e9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ URI.js is published under the [MIT license](http://www.opensource.org/licenses/m

* added .subdomain() convenience accessor
* improved internal deferred build handling
* fixed thrown Error for `URI("http://example.org").query(true)` (Issue #6)

### 1.2.0 ###

Expand Down
10 changes: 9 additions & 1 deletion src/URI.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,17 @@ URI.parseAuthority = function(string, parts) {
return URI.parseHost(string, parts);
};
URI.parseQuery = function(string) {
if (!string) {
return {};
}

// throw out the funky business - "?"[name"="value"&"]+
string = string.replace(/&+/g, '&').replace(/^\?*&*|&+$/g, '');


if (!string) {
return {};
}

var items = {},
splits = string.split('&'),
length = splits.length;
Expand Down
6 changes: 6 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ test("query", function() {
u.query('?foo');
equal(u.query(), "foo", "search: ''");
equal(u.search(), "?foo", "search: '' - query");

// parsing empty query
var t;
t = u.query('?').query(true);
t = u.query('').query(true);
t = u.href("http://example.org").query(true);
});
test("fragment", function() {
var u = new URI("http://example.org/foo.html");
Expand Down

0 comments on commit 1a691e9

Please sign in to comment.