From cc4f3c9aed4cc8c678b8d982dba993f527c4e55f Mon Sep 17 00:00:00 2001 From: Timur Ismagilov Date: Sun, 20 Mar 2022 14:50:18 +0300 Subject: [PATCH] Categories: Sanitize names before processing --- hyphae/categories/categories.go | 4 ++-- web/categories.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/hyphae/categories/categories.go b/hyphae/categories/categories.go index 4ac180f..6b69ed1 100644 --- a/hyphae/categories/categories.go +++ b/hyphae/categories/categories.go @@ -40,7 +40,7 @@ func Contents(catName string) (hyphaList []string) { var mutex sync.RWMutex -// AddHyphaToCategory adds the hypha to the category and updates the records on the disk. If the hypha is already in the category, nothing happens. +// AddHyphaToCategory adds the hypha to the category and updates the records on the disk. If the hypha is already in the category, nothing happens. Pass canonical names. func AddHyphaToCategory(hyphaName, catName string) { mutex.Lock() if node, ok := hyphaToCategories[hyphaName]; ok { @@ -58,7 +58,7 @@ func AddHyphaToCategory(hyphaName, catName string) { go saveToDisk() } -// RemoveHyphaFromCategory removes the hypha from the category and updates the records on the disk. If the hypha is not in the category, nothing happens. +// RemoveHyphaFromCategory removes the hypha from the category and updates the records on the disk. If the hypha is not in the category, nothing happens. Pass canonical names. func RemoveHyphaFromCategory(hyphaName, catName string) { mutex.Lock() if node, ok := hyphaToCategories[hyphaName]; ok { diff --git a/web/categories.go b/web/categories.go index 44381c8..cc97afc 100644 --- a/web/categories.go +++ b/web/categories.go @@ -25,8 +25,8 @@ func handlerCategory(w http.ResponseWriter, rq *http.Request) { func handlerRemoveFromCategory(w http.ResponseWriter, rq *http.Request) { util.PrepareRq(rq) var ( - hyphaName = rq.PostFormValue("hypha") - catName = rq.PostFormValue("cat") + hyphaName = util.CanonicalName(rq.PostFormValue("hypha")) + catName = util.CanonicalName(rq.PostFormValue("cat")) redirectTo = rq.PostFormValue("redirect-to") ) categories.RemoveHyphaFromCategory(hyphaName, catName) @@ -36,8 +36,8 @@ func handlerRemoveFromCategory(w http.ResponseWriter, rq *http.Request) { func handlerAddToCategory(w http.ResponseWriter, rq *http.Request) { util.PrepareRq(rq) var ( - hyphaName = rq.PostFormValue("hypha") - catName = rq.PostFormValue("cat") + hyphaName = util.CanonicalName(rq.PostFormValue("hypha")) + catName = util.CanonicalName(rq.PostFormValue("cat")) redirectTo = rq.PostFormValue("redirect-to") ) categories.AddHyphaToCategory(hyphaName, catName)