From 5b9adb4a59907c996336eafb19abeb636cc7f8e5 Mon Sep 17 00:00:00 2001 From: Remi Rampin Date: Thu, 3 Oct 2019 21:32:04 -0400 Subject: [PATCH] Fix unescaping of regex routes Previously, only the part before the first '(' would be correctly unescaped. --- tornado/routing.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tornado/routing.py b/tornado/routing.py index a35ac3483..e137a7284 100644 --- a/tornado/routing.py +++ b/tornado/routing.py @@ -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) -- 2.47.2