Replace \\n with \n in X-Message header

pull/145/head
Philipp Heckel 2022-02-13 09:23:55 -05:00
parent d3f71f9d0a
commit 0df8aa9a5d
2 changed files with 12 additions and 1 deletions

View File

@ -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
}

View File

@ -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.