#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: | [email protected]… |
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 14 years ago by
comment:2 follow-up: 3 Changed 14 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
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 Changed 14 years ago by
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 13 years ago by
Component: | Core → Query |
---|
by "doesn't work" I mean that it throws a nasty JS error.