diff options
author | Omer Katz <omer.drow@gmail.com> | 2019-04-14 12:43:20 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-14 12:43:20 +0300 |
commit | 0b72b7dbd14ca11479bbd48ef131067eadb39bc4 (patch) | |
tree | 1ad12412083a71ccc2c1a36e0b083beba72f2787 | |
parent | fb0a2f914dd764bc83afa2b6d1b85b66e397a5a6 (diff) | |
parent | c04af81779816118b2fb85e3ed44eba41ef5be24 (diff) | |
download | librabbitmq-0b72b7dbd14ca11479bbd48ef131067eadb39bc4.tar.gz |
Merge pull request #133 from davidszotten/handle_nonascii_headers
handle non-ascii headers
-rw-r--r-- | Modules/_librabbitmq/connection.c | 2 | ||||
-rw-r--r-- | tests/test_functional.py | 9 |
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): |