]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Accept None (i.e. unmatched optional groups) when extracting parameters from
authorBen Darnell <bdarnell@beaker.local>
Tue, 20 Jul 2010 17:25:25 +0000 (10:25 -0700)
committerBen Darnell <bdarnell@beaker.local>
Tue, 20 Jul 2010 17:25:25 +0000 (10:25 -0700)
the path.

http://github.com/facebook/tornado/issues/issue/115

tornado/web.py

index 3beac2390944e9e95a6f1705039d39b675742cc5..646fe067bbd9ed81da9cd22fc8870fbbad62c72b 100644 (file)
@@ -1060,16 +1060,21 @@ class Application(object):
             for spec in handlers:
                 match = spec.regex.match(request.path)
                 if match:
+                    # None-safe wrapper around urllib.unquote to handle
+                    # unmatched optional groups correctly
+                    def unquote(s):
+                        if s is None: return s
+                        return urllib.unquote(s)
                     handler = spec.handler_class(self, request, **spec.kwargs)
                     # Pass matched groups to the handler.  Since
                     # match.groups() includes both named and unnamed groups,
                     # we want to use either groups or groupdict but not both.
-                    kwargs = dict((k, urllib.unquote(v))
+                    kwargs = dict((k, unquote(v))
                                   for (k, v) in match.groupdict().iteritems())
                     if kwargs:
                         args = []
                     else:
-                        args = [urllib.unquote(s) for s in match.groups()]
+                        args = [unquote(s) for s in match.groups()]
                     break
             if not handler:
                 handler = ErrorHandler(self, request, 404)