From 8280e5b0adea54ccd33f9b1a5d911cc11a000995 Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Thu, 18 Nov 2021 14:21:00 -0500 Subject: [PATCH] Do not allow empty messages --- server/cache_sqlite.go | 3 +++ server/server.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/server/cache_sqlite.go b/server/cache_sqlite.go index 89e932e8..e1c18f6c 100644 --- a/server/cache_sqlite.go +++ b/server/cache_sqlite.go @@ -68,6 +68,9 @@ func (c *sqliteCache) Messages(topic string, since sinceTime) ([]*message, error if err := rows.Scan(&id, ×tamp, &msg); err != nil { return nil, err } + if msg == "" { + msg = " " // Hack: never return empty messages; this should not happen + } messages = append(messages, &message{ ID: id, Time: timestamp, diff --git a/server/server.go b/server/server.go index 07b9973c..3ccc86a9 100644 --- a/server/server.go +++ b/server/server.go @@ -243,6 +243,9 @@ func (s *Server) handlePublish(w http.ResponseWriter, r *http.Request, v *visito return err } m := newDefaultMessage(t.id, string(b)) + if m.Message == "" { + return errHTTPBadRequest + } if err := t.Publish(m); err != nil { return err }