From c04af81779816118b2fb85e3ed44eba41ef5be24 Mon Sep 17 00:00:00 2001 From: David Szotten Date: Thu, 11 Apr 2019 16:02:19 +0100 Subject: handle non-ascii headers --- Modules/_librabbitmq/connection.c | 2 +- tests/test_functional.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Modules/_librabbitmq/connection.c b/Modules/_librabbitmq/connection.c index ee9b122..3ace2e3 100644 --- a/Modules/_librabbitmq/connection.c +++ b/Modules/_librabbitmq/connection.c @@ -320,7 +320,7 @@ PyDict_ToAMQTable(amqp_connection_state_t conn, PyObject *src, amqp_pool_t *pool is_unicode = PyUnicode_Check(dvalue); if (is_unicode || PyBytes_Check(dvalue)) { if (is_unicode) { - if ((dvalue = PyUnicode_AsASCIIString(dvalue)) == NULL) + if ((dvalue = PyUnicode_AsEncodedString(dvalue, "utf-8", "strict")) == NULL) goto error; } AMQTable_SetStringValue(&dst, diff --git a/tests/test_functional.py b/tests/test_functional.py index 03d6276..cd7c9dc 100644 --- a/tests/test_functional.py +++ b/tests/test_functional.py @@ -1,3 +1,4 @@ +# coding: utf-8 from __future__ import absolute_import from six.moves import xrange @@ -30,6 +31,14 @@ class test_Channel(unittest.TestCase): self.assertGreater(self.channel.queue_purge(TEST_QUEUE), 2) self.channel.basic_publish(message, TEST_QUEUE, TEST_QUEUE) self.channel.basic_publish(message, TEST_QUEUE, TEST_QUEUE) + + def test_nonascii_headers(self): + message = Message( + channel=self.channel, + body='the quick brown fox jumps over the lazy dog', + properties=dict(content_type='application/json', + content_encoding='utf-8', + headers={'key': '¯\_(ツ)_/¯'})) self.channel.basic_publish(message, TEST_QUEUE, TEST_QUEUE) def _queue_declare(self): -- cgit v1.2.1