STOMP: confirm utf-8 handling

(cherry picked from commit 0ec25997b6)
This commit is contained in:
Iliia Khaprov 2025-05-06 13:51:37 +02:00 committed by Mergify
parent 1b7d66808a
commit 0d284b0ec2
2 changed files with 24 additions and 3 deletions

View File

@ -92,13 +92,13 @@ parse_resume_mid_command(_) ->
{ok, #stomp_frame{command = "COMMAND"}, _Rest} = parse(Second, Resume).
parse_resume_mid_header_key(_) ->
First = "COMMAND\nheade",
First = "COMMAND\nhead",
Second = "r1:value1\n\n\0",
{more, Resume} = parse(First),
{ok, Frame = #stomp_frame{command = "COMMAND"}, _Rest} =
parse(Second, Resume),
?assertEqual({ok, "value1"},
rabbit_stomp_frame:header(Frame, "header1")).
rabbit_stomp_frame:header(Frame, binary_to_list(<<"headꙕr1"/utf8>>))).
parse_resume_mid_header_val(_) ->
First = "COMMAND\nheader1:val",
@ -215,7 +215,7 @@ headers_escaping_roundtrip_without_trailing_lf(_) ->
parse(Content) ->
parse(Content, rabbit_stomp_frame:initial_state()).
parse(Content, State) ->
rabbit_stomp_frame:parse(list_to_binary(Content), State).
rabbit_stomp_frame:parse(unicode:characters_to_binary(Content), State).
parse_complete(Content) ->
{ok, Frame = #stomp_frame{command = Command}, State} = parse(Content),

View File

@ -119,6 +119,27 @@ class TestParsing(unittest.TestCase):
'hello\n\0')
self.match(resp, self.cd.recv(4096).decode('utf-8'))
@connect(['cd'])
def test_unicode(self):
cmd = ('\n'
'SUBSCRIBE\n'
'destination:/exchange/amq.fanout\n'
'\n\x00\n'
'SEND\n'
'destination:/exchange/amq.fanout\n'
'headꙕr1:valꙕe1\n\n'
'hello\n\x00')
self.cd.sendall(cmd.encode('utf-8'))
resp = ('MESSAGE\n'
'destination:/exchange/amq.fanout\n'
'message-id:Q_/exchange/amq.fanout@@session-(.*)\n'
'redelivered:false\n'
'headꙕr1:valꙕe1\n'
'content-length:6\n'
'\n'
'hello\n\0')
self.match(resp, self.cd.recv(4096).decode('utf-8'))
@connect(['cd'])
def test_send_without_content_type_binary(self):
msg = 'hello'