[Checkins] SVN: zope.app.file/trunk/ fix filenames when uploading from IE
Dan Korostelev
nadako at gmail.com
Fri Sep 5 15:30:26 EDT 2008
Log message for revision 90898:
fix filenames when uploading from IE
Changed:
U zope.app.file/trunk/CHANGES.txt
U zope.app.file/trunk/src/zope/app/file/browser/file.py
U zope.app.file/trunk/src/zope/app/file/browser/file.txt
U zope.app.file/trunk/src/zope/app/file/browser/image.py
-=-
Modified: zope.app.file/trunk/CHANGES.txt
===================================================================
--- zope.app.file/trunk/CHANGES.txt 2008-09-05 19:24:05 UTC (rev 90897)
+++ zope.app.file/trunk/CHANGES.txt 2008-09-05 19:30:25 UTC (rev 90898)
@@ -5,6 +5,9 @@
3.5.0 (unreleased)
------------------
+- Bug: Get actual filename instead of full filesystem path when adding file/image
+ using Internet Explorer.
+
- Using IDCTimes interface instead of IZopeDublinCore to determine the
modification date of a file.
Modified: zope.app.file/trunk/src/zope/app/file/browser/file.py
===================================================================
--- zope.app.file/trunk/src/zope/app/file/browser/file.py 2008-09-05 19:24:05 UTC (rev 90897)
+++ zope.app.file/trunk/src/zope/app/file/browser/file.py 2008-09-05 19:30:25 UTC (rev 90898)
@@ -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/trunk/src/zope/app/file/browser/file.txt
===================================================================
--- zope.app.file/trunk/src/zope/app/file/browser/file.txt 2008-09-05 19:24:05 UTC (rev 90897)
+++ zope.app.file/trunk/src/zope/app/file/browser/file.txt 2008-09-05 19:30:25 UTC (rev 90898)
@@ -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/trunk/src/zope/app/file/browser/image.py
===================================================================
--- zope.app.file/trunk/src/zope/app/file/browser/image.py 2008-09-05 19:24:05 UTC (rev 90897)
+++ zope.app.file/trunk/src/zope/app/file/browser/image.py 2008-09-05 19:30:25 UTC (rev 90898)
@@ -18,7 +18,7 @@
__docformat__ = 'restructuredtext'
from zope.size.interfaces import ISized
-from zope.app.file.browser.file import FileView
+from zope.app.file.browser.file import FileView, cleanupFileName
from zope.traversing.browser.absoluteurl import absoluteURL
@@ -107,6 +107,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