Ticket #8857 (closed defect: fixed)

Opened 6 years ago

Last modified 4 years ago

Browse fails to download some files with non-ascii characters

Reported by: tomeu Owned by: godiard
Priority: normal Milestone: 10.1.3
Component: browse-activity Version:
Keywords: Cc: reuben, rgs1, cjl, godiard
Action Needed: no action Verified: no
Deployments affected: Blocked By:
Blocking:

Description

Raúl Gutiérrez Segalés reported:

This is on build 765. When I try to download an attachment that has a filename with accents Browse does nothing and I get this on it's log:

ERROR:xpcom:Unhandled exception calling 'int8 promptForSaveToFile(in
nsISomething, in nsISomething, in wstring, in wstring, in boolean, out
retval nsISomething);'
Traceback (most recent call last):
 File "/usr/lib/xulrunner-1.9/python/xpcom/server/policy.py", line 277,
in _CallMethod_
   return 0, func(*params)
 File "/home/olpc/Activities/Browse.activity/downloadmanager.py", line
100, in promptForSaveToFile
   fd, file_path = tempfile.mkstemp(dir=_temp_path, prefix=base_name,
suffix=extension)
 File "/usr/lib/python2.5/tempfile.py", line 302, in mkstemp
   return _mkstemp_inner(dir, prefix, suffix, flags)
 File "/usr/lib/python2.5/tempfile.py", line 236, in _mkstemp_inner
   fd = _os.open(file, flags, 0600)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf3' in
position 64: ordinal not in range(128)
1224543813.083328 ERROR xpcom: Unhandled exception calling 'int8
promptForSaveToFile(in nsISomething, in nsISomething, in wstring, in
wstring, in boolean, out retval nsISomething);'
Traceback (most recent call last):
 File "/usr/lib/xulrunner-1.9/python/xpcom/server/policy.py", line 277,
in _CallMethod_
   return 0, func(*params)
 File "/home/olpc/Activities/Browse.activity/downloadmanager.py", line
100, in promptForSaveToFile
   fd, file_path = tempfile.mkstemp(dir=_temp_path, prefix=base_name,
suffix=extension)
 File "/usr/lib/python2.5/tempfile.py", line 302, in mkstemp
   return _mkstemp_inner(dir, prefix, suffix, flags)
 File "/usr/lib/python2.5/tempfile.py", line 236, in _mkstemp_inner
   fd = _os.open(file, flags, 0600)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf3' in
position 64: ordinal not in range(128)
ERROR:xpcom:Unhandled exception calling 'int8 show(in nsISomething, in
nsISomething, in uint32);'
Traceback (most recent call last):
 File "/usr/lib/xulrunner-1.9/python/xpcom/server/policy.py", line 277,
in _CallMethod_
   return 0, func(*params)
 File "/home/olpc/Activities/Browse.activity/downloadmanager.py", line
108, in show
   launcher.saveToDisk(None, False)
 File "<XPCOMObject method 'saveToDisk'>", line 3, in saveToDisk
Exception: -2147467259 (-2147467259)
1224543813.107100 ERROR xpcom: Unhandled exception calling 'int8 show(in
nsISomething, in nsISomething, in uint32);'
Traceback (most recent call last):
 File "/usr/lib/xulrunner-1.9/python/xpcom/server/policy.py", line 277,
in _CallMethod_
   return 0, func(*params)
 File "/home/olpc/Activities/Browse.activity/downloadmanager.py", line
108, in show
   launcher.saveToDisk(None, False)
 File "<XPCOMObject method 'saveToDisk'>", line 3, in saveToDisk
Exception: -2147467259 (-2147467259)

Change History

  Changed 6 years ago by tomeu

One possible solution, though I haven't been able to reproduce this bug:

diff --git a/downloadmanager.py b/downloadmanager.py
index c6c0e1a..5e45f03 100644
--- a/downloadmanager.py
+++ b/downloadmanager.py
@@ -20,6 +20,7 @@ from gettext import gettext as _
 import time
 import tempfile
 import urlparse
+import urllib
 
 import gtk
 from xpcom.nsError import *
@@ -87,6 +88,7 @@ class HelperAppLauncherDialog:
         dest_file = file_class.createInstance(interfaces.nsILocalFile)
 
         if default_file:
+            default_file = default_file.encode('utf-8', 'replace')
             base_name, extension = os.path.splitext(default_file)
         else:
             base_name = ''
@@ -247,6 +249,7 @@ class Download:
         else:
             path = urlparse.urlparse(self._source.spec).path
             location, file_name = os.path.split(path)
+            file_name = urllib.unquote(file_name.encode('utf-8', 'replace'))
             return file_name
 
     def _create_journal_object(self):

  Changed 6 years ago by reuben

  • cc reuben added

  Changed 6 years ago by rgs1

  • cc rgs1 added

The patch proposed by Tomeu fixes the problem.

To reproduce: - create a file (on any computer) with accent on its filename - send this to an email account as attachment (to an account that can be accessed

by a Webmail client)

- try to download the attached file by accessing the Webmail with Browse

  Changed 6 years ago by tomeu

  • keywords 8.2.1:? added
  • next_action changed from never set to code
  • milestone changed from Not Triaged to 8.2.1

pushed to master, leaving the ticket open for 8.2.x

  Changed 6 years ago by mstone-xmlrpc

  • keywords cjbfor9.1.0 added
  • milestone changed from 8.2.1 to 9.1.0

Pushing out to 9.1.0, per edmcnierney's request.

follow-up: ↓ 7   Changed 4 years ago by cjl

  • cc cjl added

Tomeu, can this ticket be closed or migrated to bugs.sugarlabs.org?

in reply to: ↑ 6   Changed 4 years ago by tomeu

Replying to cjl:

Tomeu, can this ticket be closed or migrated to bugs.sugarlabs.org?

I think it could be closed, but someone should check. If it was not fixed yet in all the versions of Sugar that OLPC cares about, it may be good to leave it open here pointing to the upstream bug at bugs.sugarlabs.org

  Changed 4 years ago by godiard

I have tested in 117 and needed to aplly the following change:

diff --git a/downloadmanager.py b/downloadmanager.py
index 24d3911..8736af5 100644
--- a/downloadmanager.py
+++ b/downloadmanager.py
@@ -137,8 +137,9 @@ class Download:
         self._last_update_percent = 0
         self._stop_alert = None
 
-        dom_window = _dest_to_window[self._target_file.path]
-        del _dest_to_window[self._target_file.path]
+        file_path = self._target_file.path.encode('utf-8', 'replace')
+        dom_window = _dest_to_window[file_path]
+        del _dest_to_window[file_path]
 
         view = hulahop.get_view_for_window(dom_window)
         logging.debug('Download.init dom_window: %r' % dom_window)

In Browse 108 (the version in 10.1.2) the solution it's the same.

  Changed 4 years ago by Quozl

  • keywords 8.2.1:? cjbfor9.1.0 removed
  • priority changed from high to normal
  • next_action changed from code to package
  • milestone changed from 9.1.0-cancelled to 10.1.3

Reviewed.

  Changed 4 years ago by godiard

  • cc godiard added

  Changed 4 years ago by erikos

Patch looks good to me. Gonzalo can you please make sure this gets fixed in upstream as well? Thanks.

  Changed 4 years ago by godiard

pushed

  Changed 4 years ago by erikos

  • next_action changed from package to test in build

Will be in 353.

  Changed 4 years ago by greenfeld

I was able to download files with various accented characters in them with Browse, but the Download start/completion dialogs (along with the Journal) presumed that the file name downloaded was either null or an empty string.

  Changed 4 years ago by erikos

  • owner changed from erikos to godiard
  • next_action changed from test in build to diagnose

  Changed 4 years ago by erikos

 http://www.cerlyn.com/q/ here is a good test case that it does not work yet.

  Changed 4 years ago by erikos

  • next_action changed from diagnose to review

  Changed 4 years ago by erikos

  • next_action changed from review to package

Sascha did approve it as well, will be in the next version of Browse.

  Changed 4 years ago by godiard

I pushed it in 0.84 branch

  Changed 4 years ago by erikos

  • next_action changed from package to test in build

Is in build 355 (browse 108.2)

  Changed 4 years ago by erikos

Works now in 355 for me.

  Changed 4 years ago by greenfeld

  • status changed from new to closed
  • next_action changed from test in build to no action
  • resolution set to fixed

Tested in 10.1.3 os365 that I could download an iso-8859-1 filename with accented (high-ASCII) characters, and that it appeared correctly in the journal.

Also tried to trick the engine by using "convmv" to translate this filename from iso-8859-1 to utf-8 and uploaded it to an iso-8859-1 server. But the browser was able to download with the proper filename (just like Firefox could), even though the iso-8859-1 encoded directory listing page showed the name incorrectly.

Note: See TracTickets for help on using tickets.