diff --git a/cmd/add.go b/cmd/add.go index 23a059d..3a2ea59 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -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") } diff --git a/cmd/update.go b/cmd/update.go index 73f2d5e..889ed32 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -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