Make url parsing more robust

There are some edge cases resulting from parse_url that weren't being taken care of.

Specifically, when there was no path part, or query part of the passed url, a warning was being output in the body of the response, breaking the JSON that was supposed to be emitted by an ajax response.

The warning was that the array key 'query' or 'path' did not exist when checking `$parsed['query']`

This fixes by defensively checking the result of parse_url to make sure the array key exists first.