]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Fix unescaping of regex routes 2745/head
authorRemi Rampin <r@remirampin.com>
Fri, 4 Oct 2019 01:32:04 +0000 (21:32 -0400)
committerRemi Rampin <r@remirampin.com>
Fri, 4 Oct 2019 15:24:44 +0000 (11:24 -0400)
Previously, only the part before the first '(' would be correctly
unescaped.

tornado/routing.py

index a35ac3483aadc0dfd05332a9b66261416dabf05f..e137a7284677fabbee658d1ef806da073c59608f 100644 (file)
@@ -627,7 +627,13 @@ class PathMatches(Matcher):
             if ")" in fragment:
                 paren_loc = fragment.index(")")
                 if paren_loc >= 0:
-                    pieces.append("%s" + fragment[paren_loc + 1 :])
+                    try:
+                        unescaped_fragment = re_unescape(fragment[paren_loc + 1 :])
+                    except ValueError:
+                        # If we can't unescape part of it, we can't
+                        # reverse this url.
+                        return (None, None)
+                    pieces.append("%s" + unescaped_fragment)
             else:
                 try:
                     unescaped_fragment = re_unescape(fragment)