1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-09-15 18:57:04 +00:00

Allow only absolute URLs in comments URL

Some feeds are using invalid URLs (random text).
This commit is contained in:
Frédéric Guillot 2020-01-04 15:18:24 -08:00
parent 8cebd985a2
commit bf632fad2e
6 changed files with 105 additions and 2 deletions

View file

@ -11,6 +11,15 @@ import (
"strings"
)
// IsAbsoluteURL returns true if the link is absolute.
func IsAbsoluteURL(link string) bool {
u, err := url.Parse(link)
if err != nil {
return false
}
return u.IsAbs()
}
// AbsoluteURL converts the input URL as absolute URL if necessary.
func AbsoluteURL(baseURL, input string) (string, error) {
if strings.HasPrefix(input, "//") {

View file

@ -6,6 +6,21 @@ package url // import "miniflux.app/url"
import "testing"
func TestIsAbsoluteURL(t *testing.T) {
scenarios := map[string]bool{
"https://example.org/file.pdf": true,
"magnet:?xt.1=urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C&xt.2=urn:sha1:TXGCZQTH26NL6OUQAJJPFALHG2LTGBC7": true,
"invalid url": false,
}
for input, expected := range scenarios {
actual := IsAbsoluteURL(input)
if actual != expected {
t.Errorf(`Unexpected result, got %v instead of %v for %q`, actual, expected, input)
}
}
}
func TestAbsoluteURL(t *testing.T) {
scenarios := [][]string{
[]string{"https://example.org/path/file.ext", "https://example.org/folder/", "/path/file.ext"},