Description

moin 1.3 bug: AttributeError'unicode' object has no attribute 'decode' in titlesearch with an Hebrew word.

Same result with full search. Both happen only when using the search bar at the bottom of the page, but not from the FindPage or by clicking a page title.

The search pattern is already a Unicode string when some code trying to decode it.

Details

Seen in MoinMaster

Discussion

Add a decode function (to i18n?) that check the type of string before decoding:

   1 def decode(text, encoding=None, errors='strict'):
   2     """Decode string with all error checking needed and errors handling
   3 
   4     @param: text - the text to be decoded, might be allready decoded
   5     @param: encoding - the text encoding - see codecs module for supported encodings
   6     @param: errors - error handling method. for other values see:
   7     http://www.python.org/doc/current/lib/built-in-funcs.html
   8     @return: Unicode string or None if errros is strict and the decoding failed
   9     """
  10     if not encoding:
  11        encoding = config.charset
  12     try:
  13         # Decode text unless it is a unicode string
  14         if not isinstance(text, type(u'')):
  15             text = unicode(text, encoding, errors)
  16         return text        
  17     except (ValueError, UnicodeError, LookupError):
  18         # Unkown encodings or encoding failure 
  19         return None

Then use only this function to decode everywhere in the code, becuase thes encoding bugs are always crash. Maybe we can prevent these bugs in other ways, but it is safer to check the type of string before anyway. I don't belive it will be a performance problem.

Plan


CategoryMoinMoinBugFixed

MoinMoin: MoinMoinBugs/TitleSearchCrash (last edited 2007-10-29 19:08:08 by localhost)