File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -240,9 +240,17 @@ URI.parseAuthority = function(string, parts) {
240240 return URI . parseHost ( string , parts ) ;
241241} ;
242242URI . 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 ;
Original file line number Diff line number Diff 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} ) ;
188194test ( "fragment" , function ( ) {
189195 var u = new URI ( "http://example.org/foo.html" ) ;
You can’t perform that action at this time.
0 commit comments