[Checkins] SVN: zope.app.file/branches/3.4/ fix filenames when uploading from IE
Dan Korostelev
nadako at gmail.com
Fri Sep 5 15:54:29 EDT 2008
Log message for revision 90902:
fix filenames when uploading from IE
Changed:
U zope.app.file/branches/3.4/CHANGES.txt
U zope.app.file/branches/3.4/src/zope/app/file/browser/file.py
U zope.app.file/branches/3.4/src/zope/app/file/browser/file.txt
U zope.app.file/branches/3.4/src/zope/app/file/browser/image.py
-=-
Modified: zope.app.file/branches/3.4/CHANGES.txt
===================================================================
--- zope.app.file/branches/3.4/CHANGES.txt 2008-09-05 19:34:25 UTC (rev 90901)
+++ zope.app.file/branches/3.4/CHANGES.txt 2008-09-05 19:54:28 UTC (rev 90902)
@@ -2,9 +2,16 @@
CHANGES
=======
-3.4.4 (unreleased)
+3.4.5 (unreleased)
+
+-
+
+3.4.4 (2008-09-05)
------------------
+- Bug: Get actual filename instead of full filesystem path when adding file/image
+ using Internet Explorer.
+
3.4.3 (2008-06-18)
------------------
Modified: zope.app.file/branches/3.4/src/zope/app/file/browser/file.py
===================================================================
--- zope.app.file/branches/3.4/src/zope/app/file/browser/file.py 2008-09-05 19:34:25 UTC (rev 90901)
+++ zope.app.file/branches/3.4/src/zope/app/file/browser/file.py 2008-09-05 19:54:28 UTC (rev 90902)
@@ -122,6 +122,8 @@
return self.context.data
+def cleanupFileName(filename):
+ return filename.split('\\')[-1].split('/')[-1]
class FileUpdateView(object):
@@ -135,6 +137,7 @@
filename = getattr(form["field.data"], "filename", None)
contenttype = form.get("field.contentType")
if filename:
+ filename = cleanupFileName(filename)
if not contenttype:
contenttype = guess_content_type(filename)[0]
if not form.get("add_input_name"):
Modified: zope.app.file/branches/3.4/src/zope/app/file/browser/file.txt
===================================================================
--- zope.app.file/branches/3.4/src/zope/app/file/browser/file.txt 2008-09-05 19:34:25 UTC (rev 90901)
+++ zope.app.file/branches/3.4/src/zope/app/file/browser/file.txt 2008-09-05 19:54:28 UTC (rev 90902)
@@ -127,7 +127,58 @@
>>> response.getBody().encode('base64')
'H4sICMtI6kIAA2hlbGxvLnR4dADLSM3JyecCACAwOjYGAAAA\n'
+Also, lets test a (bad) filename with full path that generates MS Internet Explorer,
+Zope should process it successfully and get the actual filename. Let's upload the
+same file with bad filename.
+ >>> print http("""
+ ... POST /+/zope.app.file.File%3D HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... Content-Type: multipart/form-data; boundary=---------------------------73793505419963331401738523176
+ ...
+ ... -----------------------------73793505419963331401738523176
+ ... Content-Disposition: form-data; name="field.contentType"
+ ...
+ ... application/octet-stream
+ ... -----------------------------73793505419963331401738523176
+ ... Content-Disposition: form-data; name="field.data"; filename="c:\\windows\\test.gz"
+ ... Content-Type: application/x-gzip
+ ...
+ ... \x1f\x8b\x08\x08\xcb\x48\xea\x42\x00\x03\x68\x65\x6c\x6c\x6f\x2e\
+ ... \x74\x78\x74\x00\xcb\x48\xcd\xc9\xc9\xe7\x02\x00\x20\x30\x3a\x36\
+ ... \x06\x00\x00\x00
+ ... -----------------------------73793505419963331401738523176
+ ... Content-Disposition: form-data; name="UPDATE_SUBMIT"
+ ...
+ ... Add
+ ... -----------------------------73793505419963331401738523176
+ ... Content-Disposition: form-data; name="add_input_name"
+ ...
+ ...
+ ... -----------------------------73793505419963331401738523176--
+ ... """)
+ HTTP/1.1 303 See Other
+ Content-Length: ...
+ Content-Type: text/html;charset=utf-8
+ Location: http://localhost/@@contents.html
+ <BLANKLINE>
+ ...
+
+The file should be saved as "test.gz", let's check it name and contents.
+
+ >>> response = http("""
+ ... GET /test.gz HTTP/1.1
+ ... """)
+ >>> print response
+ HTTP/1.1 200 OK
+ Content-Length: 36
+ Content-Type: application/octet-stream
+ <BLANKLINE>
+ ...
+
+ >>> response.getBody().encode('base64')
+ 'H4sICMtI6kIAA2hlbGxvLnR4dADLSM3JyecCACAwOjYGAAAA\n'
+
Text Files
----------
Modified: zope.app.file/branches/3.4/src/zope/app/file/browser/image.py
===================================================================
--- zope.app.file/branches/3.4/src/zope/app/file/browser/image.py 2008-09-05 19:34:25 UTC (rev 90901)
+++ zope.app.file/branches/3.4/src/zope/app/file/browser/image.py 2008-09-05 19:54:28 UTC (rev 90902)
@@ -19,7 +19,7 @@
from zope.size.interfaces import ISized
from zope.app import zapi
-from zope.app.file.browser.file import FileView
+from zope.app.file.browser.file import FileView, cleanupFileName
class ImageData(FileView):
@@ -108,6 +108,6 @@
filename = getattr(self.request.form.get("field.data"),
"filename", None)
if filename is not None:
- self.request.form["add_input_name"] = filename
+ self.request.form["add_input_name"] = cleanupFileName(filename)
return super(ImageAdd,self).update()
More information about the Checkins
mailing list