Add error checking for URL validity

This commit is contained in:
Justin Hawkins 2022-06-10 11:23:55 +09:30
parent 9e7914c9a1
commit 742f42115f
2 changed files with 15 additions and 0 deletions

View File

@ -1,9 +1,11 @@
package db
import (
"errors"
"fmt"
"io"
"log"
"strings"
"sync"
"time"
@ -32,6 +34,12 @@ func NewBookmarkManager(db *DB) *BookmarkManager {
// if this bookmark already exists (based on URL match).
// The entity.Bookmark ID field will be updated.
func (m *BookmarkManager) AddBookmark(bm *entity.Bookmark) error {
if strings.Index(bm.URL, "https://") != 0 &&
strings.Index(bm.URL, "http://") != 0 {
return errors.New("URL must begin with http:// or https://")
}
existing := entity.Bookmark{}
err := m.db.store.FindOne(&existing, bolthold.Where("URL").Eq(bm.URL))
if err != bolthold.ErrNotFound {

View File

@ -205,6 +205,13 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
"bm": bm,
"error": err,
}
if err != nil {
data["url"] = url
data["tags"] = tags
data["tags_hidden"] = c.PostForm("tags_hidden")
}
c.HTML(http.StatusOK, "add_url_form.html", data)
})
r.POST("/add_bulk", func(c *gin.Context) {