Add error checking for URL validity
This commit is contained in:
parent
9e7914c9a1
commit
742f42115f
@ -1,9 +1,11 @@
|
|||||||
package db
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -32,6 +34,12 @@ func NewBookmarkManager(db *DB) *BookmarkManager {
|
|||||||
// if this bookmark already exists (based on URL match).
|
// if this bookmark already exists (based on URL match).
|
||||||
// The entity.Bookmark ID field will be updated.
|
// The entity.Bookmark ID field will be updated.
|
||||||
func (m *BookmarkManager) AddBookmark(bm *entity.Bookmark) error {
|
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{}
|
existing := entity.Bookmark{}
|
||||||
err := m.db.store.FindOne(&existing, bolthold.Where("URL").Eq(bm.URL))
|
err := m.db.store.FindOne(&existing, bolthold.Where("URL").Eq(bm.URL))
|
||||||
if err != bolthold.ErrNotFound {
|
if err != bolthold.ErrNotFound {
|
||||||
|
@ -205,6 +205,13 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
|||||||
"bm": bm,
|
"bm": bm,
|
||||||
"error": err,
|
"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)
|
c.HTML(http.StatusOK, "add_url_form.html", data)
|
||||||
})
|
})
|
||||||
r.POST("/add_bulk", func(c *gin.Context) {
|
r.POST("/add_bulk", func(c *gin.Context) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user