changeset 5545:1f638ed400a0

wikiutil.clean_input: avoid crash if it gets str type
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 18 Feb 2010 09:40:44 +0100
parents a7838f68fbcd
children 4f938c4c5084 369a2c879eb6
files MoinMoin/wikiutil.py
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/wikiutil.py	Sat Feb 13 18:52:25 2010 +0100
+++ b/MoinMoin/wikiutil.py	Thu Feb 18 09:40:44 2010 +0100
@@ -257,7 +257,7 @@
         replace CR, LF, TAB by whitespace
         delete control chars
 
-        @param text: unicode text to clean
+        @param text: unicode text to clean (if we get str, we decode)
         @rtype: unicode
         @return: cleaned text
     """
@@ -266,6 +266,10 @@
     if length == 0 or length > max_len:
         return u''
     else:
+        if isinstance(text, str):
+            # the translate() below can ONLY process unicode, thus, if we get
+            # str, we try to decode it using the usual coding:
+            text = text.decode(config.charset)
         return text.translate(config.clean_input_translation_map)