diff --git a/server/server.go b/server/server.go index d8c7f15a..6854dd2e 100644 --- a/server/server.go +++ b/server/server.go @@ -471,7 +471,7 @@ func (s *Server) parsePublishParams(r *http.Request, v *visitor, m *message) (ca if s.mailer == nil && email != "" { return false, false, "", false, errHTTPBadRequestEmailDisabled } - messageStr := readParam(r, "x-message", "message", "m") + messageStr := strings.ReplaceAll(readParam(r, "x-message", "message", "m"), "\\n", "\n") if messageStr != "" { m.Message = messageStr } diff --git a/server/server_test.go b/server/server_test.go index 3d1e32fb..2e40bd44 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -403,6 +403,17 @@ func TestServer_PublishViaGET(t *testing.T) { require.Greater(t, msg.Time, time.Now().Add(23*time.Hour).Unix()) } +func TestServer_PublishMessageInHeaderWithNewlines(t *testing.T) { + s := newTestServer(t, newTestConfig(t)) + + response := request(t, s, "PUT", "/mytopic", "", map[string]string{ + "Message": "Line 1\\nLine 2", + }) + msg := toMessage(t, response.Body.String()) + require.NotEmpty(t, msg.ID) + require.Equal(t, "Line 1\nLine 2", msg.Message) // \\n -> \n ! +} + func TestServer_PublishFirebase(t *testing.T) { // This is unfortunately not much of a test, since it merely fires the messages towards Firebase, // but cannot re-read them. There is no way from Go to read the messages back, or even get an error back.