[Pkg-sugar-commit] [sugar-browse-activity] 01/02: Don't choke when downloading a URL containing non-UTF-8 characters (OLPC#8857)

Jonas Smedegaard dr at jones.dk
Mon Apr 20 09:47:20 UTC 2015


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag v108.2
in repository sugar-browse-activity.

commit 6c3c6a0cce460f1560a597b9d02d6284a156c13d
Author: Gonzalo Odiard <godiard at sugarlabs.org>
Date:   Thu Nov 25 03:11:48 2010 -0300

    Don't choke when downloading a URL containing non-UTF-8 characters (OLPC#8857)
    
    A URL can contain arbitrary characters; there's no guarantee they are encoded
    using UTF-8. Using the encoding of the page that contains the URL is as good a
    guess as any.
    
    Instead of throwing an exception and failing to download the file, we will now
    record a "garbled" file name in the Journal if there's an encoding mismatch.
---
 downloadmanager.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/downloadmanager.py b/downloadmanager.py
index 82afa0f..2337779 100644
--- a/downloadmanager.py
+++ b/downloadmanager.py
@@ -296,7 +296,12 @@ class Download:
         if self._display_name:
             return self._display_name
         else:
-            path = urlparse.urlparse(self._source.spec).path
+            uri = self._source
+            if uri == None:
+                return ''
+            cls = components.classes['@mozilla.org/intl/texttosuburi;1']
+            texttosuburi = cls.getService(interfaces.nsITextToSubURI)
+            path = texttosuburi.unEscapeURIForUI(uri.originCharset, uri.spec)
             location, file_name = os.path.split(path)
             file_name = urllib.unquote(file_name.encode('utf-8', 'replace'))
             return file_name

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-sugar/sugar-browse-activity.git



More information about the pkg-sugar-commit mailing list