← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~ruinedyourlife/launchpad:fix-accentuated-filenames-lost into launchpad:master

 

Quentin Debhi has proposed merging ~ruinedyourlife/launchpad:fix-accentuated-filenames-lost into launchpad:master.

Commit message:
Fix accentuated filenames being lost

Encodes and decodes the filename to fix the wrongfully formatted filename when we try to get it back

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~ruinedyourlife/launchpad/+git/launchpad/+merge/466689

Following a [user's question](https://answers.launchpad.net/launchpad/+question/814105) concerning a file being lost, we realized the accentuated characters were the issue
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~ruinedyourlife/launchpad:fix-accentuated-filenames-lost into launchpad:master.
diff --git a/lib/lp/bugs/model/bugattachment.py b/lib/lp/bugs/model/bugattachment.py
index 064482a..2b951c7 100644
--- a/lib/lp/bugs/model/bugattachment.py
+++ b/lib/lp/bugs/model/bugattachment.py
@@ -103,8 +103,14 @@ class BugAttachment(StormBase):
 
     def getFileByName(self, filename):
         """See IBugAttachment."""
-        if self.libraryfile and filename == self.libraryfile.filename:
-            return self.libraryfile
+        if self.libraryfile:
+            try:
+                corrected_filename = filename.encode("latin1").decode("utf-8")
+            except UnicodeEncodeError:
+                corrected_filename = filename
+
+            if corrected_filename == self.libraryfile.filename:
+                return self.libraryfile
         raise NotFoundError(filename)
 
     @property