Fix relative URL allowed

This commit is contained in:
Radhi Fadlillah 2018-03-08 21:12:33 +07:00
parent fd1f190800
commit ffa2497c5f
2 changed files with 14 additions and 12 deletions

View file

@ -62,7 +62,7 @@ func addBookmark(base model.Bookmark, offline bool) (book model.Bookmark, err er
// Make sure URL valid
parsedURL, err := nurl.ParseRequestURI(book.URL)
if err != nil {
if err != nil || parsedURL.Host == "" {
return book, fmt.Errorf("URL is not valid")
}

View file

@ -101,16 +101,18 @@ func init() {
func updateBookmarks(indices []string, base model.Bookmark, offline, overwrite bool) ([]model.Bookmark, error) {
mutex := sync.Mutex{}
// Make sure URL valid
parsedURL, err := nurl.ParseRequestURI(base.URL)
if err != nil {
return []model.Bookmark{}, fmt.Errorf("URL is not valid")
}
if base.URL != "" {
// Make sure URL valid
parsedURL, err := nurl.ParseRequestURI(base.URL)
if err != nil || parsedURL.Host == "" {
return []model.Bookmark{}, fmt.Errorf("URL is not valid")
}
// Clear UTM parameters from URL
url, err := clearUTMParams(parsedURL)
if err != nil {
return []model.Bookmark{}, err
// Clear UTM parameters from URL
base.URL, err = clearUTMParams(parsedURL)
if err != nil {
return []model.Bookmark{}, err
}
}
// Read bookmarks from database
@ -123,8 +125,8 @@ func updateBookmarks(indices []string, base model.Bookmark, offline, overwrite b
return []model.Bookmark{}, fmt.Errorf("No matching index found")
}
if url != "" && len(bookmarks) == 1 {
bookmarks[0].URL = url
if base.URL != "" && len(bookmarks) == 1 {
bookmarks[0].URL = base.URL
}
// If not offline, fetch articles from internet