summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Szotten <davidszotten@gmail.com>2019-04-11 16:02:19 +0100
committerDavid Szotten <davidszotten@gmail.com>2019-04-11 16:02:19 +0100
commitc04af81779816118b2fb85e3ed44eba41ef5be24 (patch)
tree1ad12412083a71ccc2c1a36e0b083beba72f2787
parentfb0a2f914dd764bc83afa2b6d1b85b66e397a5a6 (diff)
downloadlibrabbitmq-c04af81779816118b2fb85e3ed44eba41ef5be24.tar.gz
handle non-ascii headers
-rw-r--r--Modules/_librabbitmq/connection.c2
-rw-r--r--tests/test_functional.py9
2 files changed, 10 insertions, 1 deletions
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):