diff MoinMoin/wikiutil.py @ 332:0a40d8a4057e

fixed logfile breaking when DeletePage/RenamePage comment contains CRLF chars imported from: moin--main--1.5--patch-336
author Thomas Waldmann <tw@waldmann-edv.de>
date Sun, 18 Dec 2005 20:14:48 +0000
parents 76c964712b0f
children 7da3d0f49549
line wrap: on
line diff
--- a/MoinMoin/wikiutil.py	Sun Dec 18 19:45:58 2005 +0000
+++ b/MoinMoin/wikiutil.py	Sun Dec 18 20:14:48 2005 +0000
@@ -240,6 +240,22 @@
         s = s.replace('"', "&quot;")
     return s
 
+def clean_comment(comment):
+    """ Clean comment - replace CR, LF, TAB by whitespace, delete control chars
+        TODO: move this to config, create on first call then return cached.
+    """
+    remap_chars = {
+        ord(u'\t'): u' ',
+        ord(u'\r'): u' ',
+        ord(u'\n'): u' ',
+    }
+    control_chars = u'\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f' \
+                    '\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f'
+    for c in control_chars:
+        remap_chars[c] = None
+    comment = comment.translate(remap_chars)
+    return comment
+
 def make_breakable(text, maxlen):
     """ make a text breakable by inserting spaces into nonbreakable parts
     """