Add RFC 2047 encoding support for tags

pull/713/head
binwiederhier 2023-04-24 13:00:14 -04:00
parent 35eac5b9ad
commit 59a5077713
2 changed files with 6 additions and 0 deletions

View File

@ -892,6 +892,9 @@ func (s *Server) parsePublishParams(r *http.Request, m *message) (cache bool, fi
return false, false, "", false, errHTTPBadRequestPriorityInvalid return false, false, "", false, errHTTPBadRequestPriorityInvalid
} }
m.Tags = readCommaSeparatedParam(r, "x-tags", "tags", "tag", "ta") m.Tags = readCommaSeparatedParam(r, "x-tags", "tags", "tag", "ta")
for i, t := range m.Tags {
m.Tags[i] = maybeDecodeHeader(t)
}
delayStr := readParam(r, "x-delay", "delay", "x-at", "at", "x-in", "in") delayStr := readParam(r, "x-delay", "delay", "x-at", "at", "x-in", "in")
if delayStr != "" { if delayStr != "" {
if !cache { if !cache {

View File

@ -2474,12 +2474,15 @@ func TestServer_PublishWithUTF8MimeHeader(t *testing.T) {
"X-Filename": "some attachment.txt", "X-Filename": "some attachment.txt",
"X-Message": "=?UTF-8?B?8J+HqfCfh6o=?=", "X-Message": "=?UTF-8?B?8J+HqfCfh6o=?=",
"X-Title": "=?UTF-8?B?bnRmeSDlvojmo5I=?=, no really I mean it! =?UTF-8?Q?This is q=C3=BC=C3=B6ted-print=C3=A4ble.?=", "X-Title": "=?UTF-8?B?bnRmeSDlvojmo5I=?=, no really I mean it! =?UTF-8?Q?This is q=C3=BC=C3=B6ted-print=C3=A4ble.?=",
"X-Tags": "=?UTF-8?B?8J+HqfCfh6o=?=, =?UTF-8?B?bnRmeSDlvojmo5I=?=",
}) })
require.Equal(t, 200, response.Code) require.Equal(t, 200, response.Code)
m := toMessage(t, response.Body.String()) m := toMessage(t, response.Body.String())
require.Equal(t, "🇩🇪", m.Message) require.Equal(t, "🇩🇪", m.Message)
require.Equal(t, "ntfy 很棒, no really I mean it! This is qüöted-printäble.", m.Title) require.Equal(t, "ntfy 很棒, no really I mean it! This is qüöted-printäble.", m.Title)
require.Equal(t, "some attachment.txt", m.Attachment.Name) require.Equal(t, "some attachment.txt", m.Attachment.Name)
require.Equal(t, "🇩🇪", m.Tags[0])
require.Equal(t, "ntfy 很棒", m.Tags[1])
} }
func newTestConfig(t *testing.T) *Config { func newTestConfig(t *testing.T) *Config {