Description
Bug became obvious after upgrading from Python 2.4.1 to 2.4.2 since urllib.unquote was changed in the Python standard library.
Steps to reproduce
Upload attachment with non-ascii name like äöü.txt
Look at RecentChanges
Details
- Important part of traceback showing the error:
{{{ D:\Home\MoinMoin\macro\RecentChanges.py in format_comment(request=<MoinMoin.request.RequestModPy instance>, line=<MoinMoin.logfile.editlog.EditLogLine instance>)
- 29 if line.action[:3] == 'ATT': 30 import urllib 31 filename = urllib.unquote(line.extra) 32 if line.action == 'ATTNEW': 33 comment = _("Upload of attachment '%(filename)s'.") % {'filename': filename}
filename undefined, urllib = <module 'urllib' from 'C:\Python24\Lib\urllib.py'>, urllib.unquote = <function unquote>, line = <MoinMoin.logfile.editlog.EditLogLine instance>, line.extra = u'br%C3%BCckner_sapporo_20050930.doc'
- C:\Python24\Lib\urllib.py in unquote(s=u'br%C3%BCckner_sapporo_20050930.doc') 1059 item = res[i] 1060 try: 1061 res[i] = _hextochr[item[:2]] + item[2:]
1062 except KeyError: 1063 res[i] = '%' + item
res = [u'br', u'C3', u'BCckner_sapporo_20050930.doc'], i = 1, global _hextochr = {'00': '\x00', '01': '\x01', '02': '\x02', '03': '\x03', '04': '\x04', '05': '\x05', '06': '\x06', '07': '\x07', '08': '\x08', '09': '\t', ...}, item = u'C3'
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)
doc = 'Unicode decoding error.' getitem = <bound method UnicodeDecodeError.getitem of <exceptions.UnicodeDecodeError instance>> init = <bound method UnicodeDecodeError.init of <exceptions.UnicodeDecodeError instance>> module = 'exceptions' str = <bound method UnicodeDecodeError.str of <exceptions.UnicodeDecodeError instance>> args = ('ascii', '\xc3', 0, 1, 'ordinal not in range(128)') encoding = 'ascii' end = 1 object = '\xc3' reason = 'ordinal not in range(128)' start = 0
}}}
Bug is not reproducible in this Wiki!
MoinMoin Version |
1.3.4 |
OS and Version |
Win XP Pro SR2 |
Python Version |
2.4.2 ( no Bug with 2.4.1) |
Server Setup |
Apache 2.0.54, modpython 3.2.0b |
Workaround
Apply following patch to recentChanges.py
1 --- \\Wiki\Transfer\Linke\RecentChanges.py.orig1.3.4 Mon Sep 19 10:11:38 2005 2 +++ \\Wiki\Transfer\Linke\RecentChanges.py Tue Oct 04 17:28:28 2005 3 @@ -12,6 +12,7 @@ 4 from MoinMoin import util, wikiutil 5 from MoinMoin.Page import Page 6 from MoinMoin.logfile import editlog 7 +from MoinMoin import config 8 9 _DAYS_SELECTION = [1, 2, 3, 7, 14, 30, 60, 90] 10 _MAX_DAYS = 7 11 @@ -28,7 +29,8 @@ 12 _ = request.getText 13 if line.action[:3] == 'ATT': 14 import urllib 15 - filename = urllib.unquote(line.extra) 16 + filename = urllib.unquote(line.extra.encode(config.charset)) 17 + filename = filename.decode(config.charset) 18 if line.action == 'ATTNEW': 19 comment = _("Upload of attachment '%(filename)s'.") % {'filename': filename} 20 elif line.action == 'ATTDEL':
Discussion
Please upgrade to 1.3.5. I'm not sure it will work there, but we can't support old versions of 1.3. A similar patch like you suggest was made in 1.5 branch few weeks ago.
Thanks Nir. Upgrading will not help. The 1.3.4 and 1.3.5 releases have the same problem in recentChanges.py. For me there is no need to upgrade since the problem is solved. Good to hear that this problem is already fixed in 1.5. I am really looking forward to the 1.5 release!
You will have to apply similar patch to info action code, or Unicode attachments names in the page history will be displayed in a wrong way, or may raise the same exception that you get with Python 2.4.2.
You are right. The Code for the info in AttachFile.py is also buggy. But it will not raise an exception with Python 2.4.2 and thus is less severe.
- Also history in wikiaction.py has to be fixed! (also gives no exception, but displays names in wrong way)
You can get the patches used in 1.5 with tla:
tla get arch@arch.thinkmo.de--2003-archives/moin--main--1.3--patch-925 tla get arch@arch.thinkmo.de--2003-archives/moin--main--1.3--patch-932
Plan
- Priority:
Assigned to: ThomasWaldmann
- Status: should be fixed in 1.5 patch-103