fix HostnamePort matches(URI) and new tests (ex #2453)

Added new test cases, trying to cover all possible scenarios when possible, and slightly refactored the class code to meet changes in matches(URI).
Any feedback is always appreciated.
Thank you.