1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-06-15 19:15:24 +00:00

🐛 Recog. colon-only scheme URLs and add normalizeURL tests

This commit is contained in:
makeworld 2020-08-27 19:57:06 -04:00
parent 6de2b355b5
commit dbe87a3e99
5 changed files with 39 additions and 7 deletions

View File

@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Two digit (and higher) link texts are now in line with one digit ones (#60)
- Race condition when reloading pages, could have caused the cache to still be used
- Prevent panic (crash) when the server sends an error with an empty meta string (#73)
- URLs with with colon-only schemes (like `mailto:`) are properly recognized
## [1.4.0] - 2020-07-28

View File

@ -549,6 +549,10 @@ func URL(u string) {
return
}
if !strings.HasPrefix(u, "//") && !strings.HasPrefix(u, "gemini://") && !strings.Contains(u, "://") {
// Assume it's a Gemini URL
u = "gemini://" + u
}
go goURL(tabs[curTab], u)
}

View File

@ -83,13 +83,6 @@ func normalizeURL(u string) string {
return u
}
if !strings.Contains(u, "://") && !strings.HasPrefix(u, "//") {
// No scheme at all in the URL
parsed, err = url.Parse("gemini://" + u)
if err != nil {
return u
}
}
if parsed.Scheme == "" {
// Always add scheme
parsed.Scheme = "gemini"

33
display/util_test.go Normal file
View File

@ -0,0 +1,33 @@
package display
import (
"testing"
)
var normalizeURLTests = []struct {
u string
expected string
}{
{"gemini://example.com:1965/", "gemini://example.com/"},
{"gemini://example.com", "gemini://example.com/"},
{"//example.com", "gemini://example.com/"},
{"//example.com:1965", "gemini://example.com/"},
{"//example.com:123/", "gemini://example.com:123/"},
{"gemini://example.com/", "gemini://example.com/"},
{"gemini://example.com/#fragment", "gemini://example.com/"},
{"gemini://example.com#fragment", "gemini://example.com/"},
{"gemini://user@example.com/", "gemini://example.com/"},
// Other schemes, URL isn't modified
{"mailto:example@example.com", "mailto:example@example.com"},
{"magnet:?xt=urn:btih:test", "magnet:?xt=urn:btih:test"},
{"https://example.com", "https://example.com"},
}
func TestNormalizeURL(t *testing.T) {
for _, tt := range normalizeURLTests {
actual := normalizeURL(tt.u)
if actual != tt.expected {
t.Errorf("normalizeURL(%s): expected %s, actual %s", tt.u, tt.expected, actual)
}
}
}

1
go.sum
View File

@ -203,6 +203,7 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
github.com/spf13/viper v1.7.0 h1:xVKxvI7ouOI5I+U9s2eeiUfMaWBVoXA3AWskkrqK0VM=
github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=