Opened 11 years ago

Closed 11 years ago

Last modified 10 years ago

#7384 closed enhancement (invalid)

var q = dojo.queryToObject((new dojo._Url(document.location)).query); fails on URL without query string

Reported by: Josh Trutwin Owned by: anonymous
Priority: low Milestone: tbd
Component: Query Version: 1.1.1
Keywords: query dojo._Url null Cc: josh@…
Blocked By: Blocking:

Description

var q = dojo.queryToObject((new dojo._Url(document.location)).query);

The above one-liner doesn't work if the document.location URL does not have anything in the query string as the value returned by dojo._Url has null in the .query property.

Suggest changing .query to empty hash {} so the above will work instead of requiring to be split into multiple lines:

var u = new dojo._Url(document.location); if (! u.query) { return; } var q = dojo.queryToObject(u.query);

Thanks!

Change History (4)

comment:1 Changed 11 years ago by Josh Trutwin

by "doesn't work" I mean that it throws a nasty JS error.

comment:2 Changed 11 years ago by James Burke

Resolution: invalid
Status: newclosed

You could also do your code like this:

var q = dojo.queryToObject((new dojo._Url(document.location)).query || {}); 

It does not seem right to return an empty hash for query. What if you do a dojo._Url and want to know if it has a query value? That sort of test becomes cumbersome if query is just {}. Right now, it is just if (url.query).

comment:3 in reply to:  2 Changed 11 years ago by Josh Trutwin

Replying to jburke:

You could also do your code like this:

var q = dojo.queryToObject((new dojo._Url(document.location)).query || {}); 

It does not seem right to return an empty hash for query. What if you do a dojo._Url and want to know if it has a query value? That sort of test becomes cumbersome if query is just {}. Right now, it is just if (url.query).

Works for me - I was talking on IRC about this a while back and was suggested to file bug, but certainly this is an easy solution.

Thanks

comment:4 Changed 10 years ago by bill

Component: CoreQuery
Note: See TracTickets for help on using tickets.