diff MoinMoin/app.py @ 1899:f38a893334b5

new ItemNameConverter that does not match trailing slashes we do not support trailing slashes in itemnames, but for user convenience, we redirect <root_url>/itemname/ to <root_url>/itemname. this partly fixes #46.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 24 Dec 2012 00:39:45 +0100
parents 4a054063fbb0
children 20867923566a
line wrap: on
line diff
--- a/MoinMoin/app.py	Mon Dec 24 00:10:20 2012 +0100
+++ b/MoinMoin/app.py	Mon Dec 24 00:39:45 2012 +0100
@@ -100,8 +100,22 @@
     clock.stop('create_app load config')
     clock.start('create_app register')
     # register converters
-    from werkzeug.routing import PathConverter
-    app.url_map.converters['itemname'] = PathConverter
+    from werkzeug.routing import BaseConverter
+
+    class ItemNameConverter(BaseConverter):
+        """Like the default :class:`UnicodeConverter`, but it also matches
+        slashes (except at the beginning AND end).
+        This is useful for wikis and similar applications::
+
+            Rule('/<itemname:wikipage>')
+            Rule('/<itemname:wikipage>/edit')
+
+        :param map: the :class:`Map`.
+        """
+        regex = '[^/].*?[^/]'
+        weight = 200
+
+    app.url_map.converters['itemname'] = ItemNameConverter
     # register modules, before/after request functions
     from MoinMoin.apps.frontend import frontend
     frontend.before_request(before_wiki)