From 6831fe6d8997e94545f4ba03616c3a220672a7a5 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Wed, 17 Sep 2008 15:38:54 -0700 Subject: [PATCH] Fixed a bug in which the /files/preview page couldn't display unicode filenames with special characters. The problem was that the filename was encoded as UTF-8 twice, rather than once. --- controller/Files.py | 2 +- controller/test/Test_files.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/controller/Files.py b/controller/Files.py index 12d1199..e100fd1 100644 --- a/controller/Files.py +++ b/controller/Files.py @@ -420,7 +420,7 @@ class Files( object ): if not db_file or not self.__users.check_access( user_id, db_file.notebook_id ): raise Access_error() - filename = db_file.filename.replace( '"', r"\"" ).encode( "utf8" ) + filename = db_file.filename.replace( '"', r"\"" ) return dict( file_id = file_id, diff --git a/controller/test/Test_files.py b/controller/test/Test_files.py index 6a59b36..29fd597 100644 --- a/controller/test/Test_files.py +++ b/controller/test/Test_files.py @@ -472,6 +472,30 @@ class Test_files( Test_controller ): assert result[ u"filename" ] == self.filename assert result[ u"quote_filename" ] == False + def test_preview_with_unicode_filename( self ): + self.login() + + self.http_upload( + "/files/upload?file_id=%s" % self.file_id, + dict( + notebook_id = self.notebook.object_id, + note_id = self.note.object_id, + ), + filename = self.unicode_filename, + file_data = self.IMAGE_DATA, + content_type = self.content_type, + session_id = self.session_id, + ) + + result = self.http_get( + "/files/preview?file_id=%s" % self.file_id, + session_id = self.session_id, + ) + + assert result[ u"file_id" ] == self.file_id + assert result[ u"filename" ] == self.unicode_filename + assert result[ u"quote_filename" ] == False + def test_preview_with_quote_filename_true( self ): self.login()