Skip to content

Commit

Permalink
Deal with UTF-8 filenames until https://bugs.launchpad.net/zope2/+bug…
Browse files Browse the repository at this point in the history
…/499696 is fixed.

Fixes http://code.google.com/p/dexterity/issues/detail?id=148

svn path=/plone.formwidget.namedfile/trunk/; revision=46983
  • Loading branch information
Martijn Pieters committed Jan 21, 2011
1 parent 5ef07c4 commit ba9da3f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 3 additions & 2 deletions docs/HISTORY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Changelog
1.0b9 (unreleased)
------------------

* Fix handling of unicode filenames when quoting the URL.
[rossp]
* Fix handling of unicode filenames when converting or quoting the URL.
Fixes http://code.google.com/p/dexterity/issues/detail?id=148
[rossp, mj]

* Added Spanish translations.
[dukebody]
Expand Down
6 changes: 4 additions & 2 deletions plone/formwidget/namedfile/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ def toFieldValue(self, value):
headers = value.headers
filename = safe_basename(value.filename)

if filename is not None:
filename = unicode(filename)
if filename is not None and not isinstance(filename, unicode):
# Work-around for
# https://bugs.launchpad.net/zope2/+bug/499696
filename = filename.decode('utf-8')

contentType = 'application/octet-stream'
if headers:
Expand Down
8 changes: 5 additions & 3 deletions plone/formwidget/namedfile/widget.txt
Original file line number Diff line number Diff line change
Expand Up @@ -470,15 +470,17 @@ A data string is converted to the appropriate type:
<plone.namedfile.file.NamedImage object at ...>

A FileUpload object is converted to the appropriate type, preserving filename
and content type.
and content type, and possibly handling international characters in filenames.

>>> myfile = cStringIO.StringIO('File upload contents.')
>>> aFieldStorage = FieldStorageStub(myfile, filename='random.txt', headers={'Content-Type': 'text/x-dummy'})
>>> # \xc3\xb8 is UTF-8 for a small letter o with slash
>>> aFieldStorage = FieldStorageStub(myfile, filename='rand\xc3\xb8m.txt',
... headers={'Content-Type': 'text/x-dummy'})
>>> file_obj = file_converter.toFieldValue(FileUpload(aFieldStorage))
>>> file_obj.data
'File upload contents.'
>>> file_obj.filename
u'random.txt'
u'rand\xf8m.txt'
>>> file_obj.contentType
'text/x-dummy'

Expand Down

0 comments on commit ba9da3f

Please sign in to comment.