Fixed parsing of username and password encoded in the URI

As per #1856, fixes the parsing of URI encoded usernames and password. Also fixes a bogus test where the username in the URI was not correctly encoded.