all repos — searchix @ 0cd9a2446413e9050c24ccd409bc8f97ad18076a

Search engine for NixOS, nix-darwin, home-manager and NUR users

fix: block single-character queries
Alan Pearce alan@alanpearce.eu
Sun, 23 Mar 2025 22:59:05 +0100
commit

0cd9a2446413e9050c24ccd409bc8f97ad18076a

parent

297a7a2096a12e6ac50d7b2077f2d75a7026fae4

2 files changed, 7 insertions(+), 0 deletions(-)

jump to
M internal/components/search.gointernal/components/search.go
@@ -19,6 +19,7 @@ ), 			Input(
 				ID("query"),
 				Aria("labelledby", "legend"),
+				MinLength("2"),
 				Name("query"),
 				Type("search"),
 				Value(r.Query),
M internal/server/mux.gointernal/server/mux.go
@@ -96,6 +96,12 @@ 			if r.URL.Query().Has("query") {
 				qs := r.URL.Query().Get("query")
 
+				if len(qs) < 2 {
+					errorHandler(w, r, "Query too short", http.StatusBadRequest)
+
+					return
+				}
+
 				var pageSize int = search.DefaultPageSize
 				var pageNumber = 1
 				if pg := r.URL.Query().Get("page"); pg != "" {