diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ba3915..387d42f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Bookmarks modal closes on ESC like the others (#173) - Handle empty META string (#176) - Whitespace around the URL entered in the bottom bar is stripped (#184) +- Don't break visiting IPv6 hosts when port 1965 is specified (#195) ## [1.7.2] - 2020-12-21 diff --git a/display/util.go b/display/util.go index 33495c1..a74e09c 100644 --- a/display/util.go +++ b/display/util.go @@ -105,7 +105,12 @@ func normalizeURL(u string) string { parsed.Fragment = "" // No fragments either if parsed.Port() == "1965" { // Always remove default port - parsed.Host = parsed.Hostname() + hostname := parsed.Hostname() + if strings.Contains(hostname, ":") { + parsed.Host = "[" + parsed.Hostname() + "]" + } else { + parsed.Host = parsed.Hostname() + } } // Add slash to the end of a URL with just a domain diff --git a/display/util_test.go b/display/util_test.go index 09309a8..02e1bca 100644 --- a/display/util_test.go +++ b/display/util_test.go @@ -27,6 +27,11 @@ var normalizeURLTests = []struct { {"gemini://example.com/蛸", "gemini://example.com/%E8%9B%B8"}, {"gemini://gemini.circumlunar.space/%64%6f%63%73/;;.'%66%61%71蛸%2e%67%6d%69", "gemini://gemini.circumlunar.space/docs/%3B%3B.%27faq%E8%9B%B8.gmi"}, {"gemini://example.com/?%2Ch%64ello蛸", "gemini://example.com/?%2Chdello%E8%9B%B8"}, + // IPv6 tests, see #195 + {"gemini://[::1]", "gemini://[::1]/"}, + {"gemini://[::1]:1965", "gemini://[::1]/"}, + {"gemini://[::1]/test", "gemini://[::1]/test"}, + {"gemini://[::1]:1965/test", "gemini://[::1]/test"}, } func TestNormalizeURL(t *testing.T) {