commit 4e0b131b481e8d668d2ab90542ca719f8ce7acbb
parent 5fb1f68c883d7d3f83dfdb3d10ff9d01dbd9325d
Author: breadcat <breadcat@users.noreply.github.com>
Date: Thu, 12 Mar 2026 15:43:25 +0000
Jankily fix deletion of values including slashes
Diffstat:
3 files changed, 24 insertions(+), 26 deletions(-)
diff --git a/include-files.go b/include-files.go
@@ -23,7 +23,7 @@ func fileRouter(w http.ResponseWriter, r *http.Request) {
return
}
- if len(parts) >= 7 && parts[3] == "tag" {
+ if len(parts) >= 5 && parts[3] == "tag" && parts[4] == "delete" {
tagActionHandler(w, r, parts)
return
}
diff --git a/include-viewer.go b/include-viewer.go
@@ -167,31 +167,29 @@ func getLocalIP() (string, error) {
}
func tagActionHandler(w http.ResponseWriter, r *http.Request, parts []string) {
- fileID := parts[2]
- cat, err := url.PathUnescape(parts[4])
- if err != nil {
- http.Redirect(w, r, "/file/"+fileID, http.StatusSeeOther)
- return
- }
- val, err := url.PathUnescape(parts[5])
- if err != nil {
- http.Redirect(w, r, "/file/"+fileID, http.StatusSeeOther)
- return
- }
- action := parts[6]
+ fileID := parts[2]
- if action == "delete" && r.Method == http.MethodPost {
- var tagID int
- db.QueryRow(`
- SELECT t.id
- FROM tags t
- JOIN categories c ON c.id=t.category_id
- WHERE c.name=? AND t.value=?`, cat, val).Scan(&tagID)
- if tagID != 0 {
- db.Exec("DELETE FROM file_tags WHERE file_id=? AND tag_id=?", fileID, tagID)
- }
- }
- http.Redirect(w, r, "/file/"+fileID, http.StatusSeeOther)
+ if r.Method != http.MethodPost {
+ http.Redirect(w, r, "/file/"+fileID, http.StatusSeeOther)
+ return
+ }
+
+ cat := strings.TrimSpace(r.FormValue("category"))
+ val := strings.TrimSpace(r.FormValue("value"))
+
+ if cat != "" && val != "" {
+ var tagID int
+ db.QueryRow(`
+ SELECT t.id
+ FROM tags t
+ JOIN categories c ON c.id=t.category_id
+ WHERE c.name=? AND t.value=?`, cat, val).Scan(&tagID)
+ if tagID != 0 {
+ db.Exec("DELETE FROM file_tags WHERE file_id=? AND tag_id=?", fileID, tagID)
+ }
+ }
+
+ http.Redirect(w, r, "/file/"+fileID, http.StatusSeeOther)
}
func getOrCreateCategoryAndTag(category, value string) (int, int, error) {
diff --git a/templates/file.html b/templates/file.html
@@ -13,7 +13,7 @@
<span class="file-tag-category">{{$k}}:</span><br>
{{range $i, $v := $vs}}
{{if $i}}<br> {{end}}
- <form method="post" action="/file/{{$.Data.File.ID}}/tag/{{pathEscape $k}}/{{pathEscape $v}}/delete"><button class="text-button" type="submit">x</button></form>
+ <form method="post" action="/file/{{$.Data.File.ID}}/tag/delete"><input type="hidden" name="category" value="{{$k}}"><input type="hidden" name="value" value="{{$v}}"><button class="text-button" type="submit">x</button></form>
<a href="/tag/{{pathEscape $k}}/{{pathEscape $v}}">{{$v}}</a>
{{end}}
</li>