Streamline url-parsing logic.

This is an attempt to fix the url-parsing logic to avoid clunky validation, but also not introduce regexes. I've added a test that segfaulted before this change.