LoginSignup
0
0

More than 5 years have passed since last update.

Mailman の会員検索で、マルチバイトな会員名での検索ができない

Posted at

Mailman の会員検索で、マルチバイトな会員名での検索ができないので調べてみたら、POST された検索語を decode していない、というありがちなパタンだった。

--- Mailman/Cgi/admin.py    2014-02-04 02:09:14.000000000 +0900
+++ Mailman/Cgi/admin.py    2015-04-10 15:13:58.810916527 +0900
@@ -900,12 +900,16 @@
     # The email addresses had /better/ be ASCII, but might be encoded in the
     # database as Unicodes.
     all = [_m.encode() for _m in mlist.getMembers()]
     all.sort(lambda x, y: cmp(x.lower(), y.lower()))
     # See if the query has a regular expression
     regexp = cgidata.getvalue('findmember', '').strip()
+    try:
+        regexp = regexp.decode(Utils.GetCharSet(mlist.preferred_language))
+    except:
+        pass
     if regexp:
         try:
             cre = re.compile(regexp, re.IGNORECASE)
         except re.error:
             doc.addError(_('Bad regular expression: ') + regexp)
         else:

手前の all = [_m.encode() for _m in mlist.getMembers()] が気になるけれど、メールアドレスは ASCII 文字しか使われないのでそのままにしておく。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0