incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject git commit: [#5012] avoid mongo BSON encoding error, by ensuring attachment filenames are unicode
Date Tue, 02 Oct 2012 17:35:57 GMT
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 <dbrondsema@geek.net>
Authored: Tue Oct 2 17:35:50 2012 +0000
Committer: Dave Brondsema <dbrondsema@geek.net>
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()


Mime
View raw message