You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by ke...@apache.org on 2017/09/28 13:27:45 UTC
allura git commit: [#8160] Fixes unicode acceptance in
handle_artifact_message
Repository: allura
Updated Branches:
refs/heads/kt/8160 [created] d5bc91c8f
[#8160] Fixes unicode acceptance in handle_artifact_message
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/d5bc91c8
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/d5bc91c8
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/d5bc91c8
Branch: refs/heads/kt/8160
Commit: d5bc91c8fb83e9fa85649788c3cad837ec7297ab
Parents: 78b89b4
Author: Kenton Taylor <kt...@slashdotmedia.com>
Authored: Thu Sep 28 09:13:16 2017 -0400
Committer: Kenton Taylor <kt...@slashdotmedia.com>
Committed: Thu Sep 28 09:27:01 2017 -0400
----------------------------------------------------------------------
Allura/allura/app.py | 7 ++++++-
Allura/allura/tests/test_app.py | 27 +++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/d5bc91c8/Allura/allura/app.py
----------------------------------------------------------------------
diff --git a/Allura/allura/app.py b/Allura/allura/app.py
index 6c97169..e7c1f1e 100644
--- a/Allura/allura/app.py
+++ b/Allura/allura/app.py
@@ -709,7 +709,12 @@ class Application(object):
log.info(
'Existing message_id %s found - saving this as text attachment' %
message_id)
- fp = StringIO(message['payload'])
+
+ try:
+ fp = StringIO(message['payload'].encode('utf-8'))
+ except UnicodeDecodeError as ex:
+ fp = StringIO(message['payload'])
+
post.attach(
'alternate', fp,
content_type=message.get(
http://git-wip-us.apache.org/repos/asf/allura/blob/d5bc91c8/Allura/allura/tests/test_app.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_app.py b/Allura/allura/tests/test_app.py
index 0e20905..95ef371 100644
--- a/Allura/allura/tests/test_app.py
+++ b/Allura/allura/tests/test_app.py
@@ -1,3 +1,5 @@
+# -*- coding: utf-8 -*-
+
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
@@ -121,3 +123,28 @@ def test_sitemap():
sm.extend([app.SitemapEntry('a', 'a/')[
app.SitemapEntry('d', 'd/')]])
assert len(sm.children) == 3
+
+
+@mock.patch('allura.app.Application.PostClass.query.get')
+def test_handle_artifact_unicode(qg):
+ """
+ Tests that app.handle_artifact_message can accept utf strings
+ """
+ ticket = mock.MagicMock()
+ ticket.get_discussion_thread.return_value = (mock.MagicMock(), mock.MagicMock())
+ post = mock.MagicMock()
+ qg.return_value = post
+
+ a = app.Application(c.project, c.app.config)
+
+ msg = dict(payload=u'foo ƒ†©¥˙¨ˆ', message_id=1, headers={})
+ a.handle_artifact_message(ticket, msg)
+ assert_equal(post.attach.call_args[0][1].getvalue(), 'foo ƒ†©¥˙¨ˆ')
+
+ msg = dict(payload='foo', message_id=1, headers={})
+ a.handle_artifact_message(ticket, msg)
+ assert_equal(post.attach.call_args[0][1].getvalue(), 'foo')
+
+ msg = dict(payload="\x94my quote\x94", message_id=1, headers={})
+ a.handle_artifact_message(ticket, msg)
+ assert_equal(post.attach.call_args[0][1].getvalue(), '\x94my quote\x94')
\ No newline at end of file