Skip to content

Commit 1a691e9

Browse files
committed
Fixing Issue #6 - Error thrown on .query(true) if query was null
1 parent af4ef57 commit 1a691e9

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ URI.js is published under the [MIT license](http://www.opensource.org/licenses/m
166166

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

170171
### 1.2.0 ###
171172

src/URI.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,17 @@ URI.parseAuthority = function(string, parts) {
240240
return URI.parseHost(string, parts);
241241
};
242242
URI.parseQuery = function(string) {
243+
if (!string) {
244+
return {};
245+
}
246+
243247
// throw out the funky business - "?"[name"="value"&"]+
244248
string = string.replace(/&+/g, '&').replace(/^\?*&*|&+$/g, '');
245-
249+
250+
if (!string) {
251+
return {};
252+
}
253+
246254
var items = {},
247255
splits = string.split('&'),
248256
length = splits.length;

test/test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ test("query", function() {
184184
u.query('?foo');
185185
equal(u.query(), "foo", "search: ''");
186186
equal(u.search(), "?foo", "search: '' - query");
187+
188+
// parsing empty query
189+
var t;
190+
t = u.query('?').query(true);
191+
t = u.query('').query(true);
192+
t = u.href("http://example.org").query(true);
187193
});
188194
test("fragment", function() {
189195
var u = new URI("http://example.org/foo.html");

0 commit comments

Comments
 (0)