changeset 281:8155e50e94ca

fixed crash with non-ASCII attachment filename imported from: moin--main--1.5--patch-285
author Thomas Waldmann <tw@waldmann-edv.de>
date Sun, 04 Dec 2005 11:40:42 +0000
parents 015c945277ec
children 625640dccd66
files MoinMoin/action/AttachFile.py MoinMoin/formatter/text_gedit.py MoinMoin/formatter/text_html.py MoinMoin/parser/wiki.py docs/CHANGES
diffstat 5 files changed, 24 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/AttachFile.py	Sun Dec 04 10:34:44 2005 +0000
+++ b/MoinMoin/action/AttachFile.py	Sun Dec 04 11:40:42 2005 +0000
@@ -66,11 +66,14 @@
     return attach_dir
 
 def absoluteName(url, pagename):
-    """ Get (pagename, filename) of an atatchment: link
+    """ Get (pagename, filename) of an attachment: link
+        @param url: PageName/filename.ext or filename.ext (unicode)
+        @param pagename: name of the currently processed page (unicode)
+        @rtype: tuple of unicode
+        @return: PageName, filename.ext
     """
-
-    pieces = url.split('/')
-    if len(pieces)==1:
+    pieces = url.split(u'/')
+    if len(pieces) == 1:
         return pagename, pieces[0]
     else:
         return u"/".join(pieces[:-1]), pieces[-1]
@@ -123,8 +126,15 @@
     return attach_link
 
 
-def getFilename(request, pagename, name):
-    return os.path.join(getAttachDir(request, pagename), name).encode(config.charset)
+def getFilename(request, pagename, filename):
+    """ make complete pathfilename of file "name" attached to some page "pagename"
+        @param request: request object
+        @param pagename: name of page where the file is attached to (unicode)
+        @param filename: filename of attached file (unicode)
+        @rtype: string (in config.charset encoding)
+        @return: complete path/filename of attached file
+    """
+    return os.path.join(getAttachDir(request, pagename), filename).encode(config.charset)
 
 
 def info(pagename, request):
--- a/MoinMoin/formatter/text_gedit.py	Sun Dec 04 10:34:44 2005 +0000
+++ b/MoinMoin/formatter/text_gedit.py	Sun Dec 04 11:40:42 2005 +0000
@@ -103,7 +103,7 @@
     def attachment_drawing(self, url, text, **kw):
         _ = self.request.getText
         pagename = self.page.page_name
-        image = url + '.png'
+        image = url + u'.png'
         fname = wikiutil.taintfilename(image)
         fpath = AttachFile.getFilename(self.request, pagename, fname)
         return self.image(
--- a/MoinMoin/formatter/text_html.py	Sun Dec 04 10:34:44 2005 +0000
+++ b/MoinMoin/formatter/text_html.py	Sun Dec 04 11:40:42 2005 +0000
@@ -340,13 +340,13 @@
         pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
         fname = wikiutil.taintfilename(filename)
         drawing = fname
-        fname = fname + ".png"
-        filename = filename + ".png"
+        fname = fname + u".png"
+        filename = filename + u".png"
         # fallback for old gif drawings (1.1 -> 1.2)
         fpath = AttachFile.getFilename(self.request, pagename, fname)
         if not os.path.exists(fpath):
-            gfname = fname[:-4] + ".gif"
-            gfilename = filename[:-4] + ".gif"
+            gfname = fname[:-4] + u".gif"
+            gfilename = filename[:-4] + u".gif"
             gfpath = AttachFile.getFilename(self.request, pagename, gfname)
             if os.path.exists(gfpath):
                 fname, filename, fpath = gfname, gfilename, gfpath
@@ -362,7 +362,7 @@
                   drawing and ('&drawing=%s' % wikiutil.url_quote(drawing)) or '')),
                 linktext % {'filename': self.text(fname)})
 
-        mappath = AttachFile.getFilename(self.request, pagename, drawing + '.map')
+        mappath = AttachFile.getFilename(self.request, pagename, drawing + u'.map')
         edit_link = ('%s?action=AttachFile&rename=%s&drawing=%s' % (
             wikiutil.quoteWikinameURL(pagename),
             wikiutil.url_quote_plus(fname),
--- a/MoinMoin/parser/wiki.py	Sun Dec 04 10:34:44 2005 +0000
+++ b/MoinMoin/parser/wiki.py	Sun Dec 04 11:40:42 2005 +0000
@@ -206,7 +206,7 @@
         inline = url[0] == 'i'
         drawing = url[0] == 'd'
         url = url.split(":", 1)[1]
-        url = wikiutil.url_unquote(url, want_unicode=False)
+        url = wikiutil.url_unquote(url, want_unicode=True)
         text = text or url
 
         from MoinMoin.action import AttachFile
--- a/docs/CHANGES	Sun Dec 04 10:34:44 2005 +0000
+++ b/docs/CHANGES	Sun Dec 04 11:40:42 2005 +0000
@@ -21,6 +21,7 @@
     * Fixed a few bugs in the XML formatters (dom_xml, text_xml, xml_docbook).
     * Fixed link icons. We now just use a.xxx.before where xxx is the link scheme,
       e.g. a.http.before. See theme's common.css.
+    * Hopefully fixed some issue with non-ASCII attachment filenames.
 
   Other changes:
     * Added irc:// to the builtin supported link schemas. You can remove it