Return-Path: X-Original-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BC0C4D3FB for ; Tue, 2 Oct 2012 17:35:57 +0000 (UTC) Received: (qmail 59421 invoked by uid 500); 2 Oct 2012 17:35:57 -0000 Delivered-To: apmail-incubator-allura-commits-archive@incubator.apache.org Received: (qmail 59404 invoked by uid 500); 2 Oct 2012 17:35:57 -0000 Mailing-List: contact allura-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: allura-dev@incubator.apache.org Delivered-To: mailing list allura-commits@incubator.apache.org Received: (qmail 59396 invoked by uid 99); 2 Oct 2012 17:35:57 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Oct 2012 17:35:57 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 47DBD370F7; Tue, 2 Oct 2012 17:35:57 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: brondsem@apache.org To: allura-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: git commit: [#5012] avoid mongo BSON encoding error, by ensuring attachment filenames are unicode Message-Id: <20121002173557.47DBD370F7@tyr.zones.apache.org> Date: Tue, 2 Oct 2012 17:35:57 +0000 (UTC) Updated Branches: refs/heads/db/5012 [created] 4e0d071ef [#5012] avoid mongo BSON encoding error, by ensuring attachment filenames are unicode Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/4e0d071e Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/4e0d071e Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/4e0d071e Branch: refs/heads/db/5012 Commit: 4e0d071ef079e304acccfeb68875dbb56b973bf3 Parents: 0298d85 Author: Dave Brondsema Authored: Tue Oct 2 17:35:50 2012 +0000 Committer: Dave Brondsema Committed: Tue Oct 2 17:35:50 2012 +0000 ---------------------------------------------------------------------- Allura/allura/model/attachments.py | 1 + Allura/allura/tests/model/test_filesystem.py | 8 ++++++++ 2 files changed, 9 insertions(+), 0 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/4e0d071e/Allura/allura/model/attachments.py ---------------------------------------------------------------------- diff --git a/Allura/allura/model/attachments.py b/Allura/allura/model/attachments.py index d0869c9..fcec088 100644 --- a/Allura/allura/model/attachments.py +++ b/Allura/allura/model/attachments.py @@ -42,6 +42,7 @@ class BaseAttachment(File): @classmethod def save_attachment(cls, filename, fp, content_type=None, **kwargs): + filename = h.really_unicode(filename) thumbnail_meta = dict(type="thumbnail", app_config_id=c.app.config._id) thumbnail_meta.update(kwargs) original_meta = dict(type="attachment", app_config_id=c.app.config._id) http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/4e0d071e/Allura/allura/tests/model/test_filesystem.py ---------------------------------------------------------------------- diff --git a/Allura/allura/tests/model/test_filesystem.py b/Allura/allura/tests/model/test_filesystem.py index 7ab99b5..f7d4007 100644 --- a/Allura/allura/tests/model/test_filesystem.py +++ b/Allura/allura/tests/model/test_filesystem.py @@ -162,6 +162,14 @@ class TestFile(TestCase): assert_equal(attachment.length, 500) assert_equal(attachment.filename, 'user.png') + def test_attachment_name_encoding(self): + path = os.path.join(os.path.dirname(__file__), '..', 'data', 'user.png') + fp = open(path, 'rb') + c.app.config._id = None + attachment = M.BaseAttachment.save_attachment(b'Strukturpr\xfcfung.dvi', fp, + save_original=True) + assert type(attachment) != tuple # tuple is for (img, thumb) pairs + assert_equal(attachment.filename, u'Strukturpr\xfcfung.dvi') def _assert_content(self, f, content): result = f.rfile().read()