From ce54df21ec4aa57c4eaff38117ec8d8c975962fd Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Wed, 10 Apr 2019 12:10:34 +0200 Subject: [PATCH 3/5] utils: allow string replacement in next parameters (#32140) The caller must explicitely give the replacement it covers through the replace argument taking a dictionnary. The dictionnary keys are the replacement pattern as simple strings, dictionnary values are the replacement substitution. The replacement substitution is encoded with urlparse.quote() before replacement. --- src/authentic2/utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/authentic2/utils.py b/src/authentic2/utils.py index e7fed068..7521fd08 100644 --- a/src/authentic2/utils.py +++ b/src/authentic2/utils.py @@ -907,6 +907,9 @@ def select_next_url(request, default, field_name=None, include_post=False, repla '''Select the first valid next URL''' next_url = (include_post and get_next_url(request.POST, field_name=field_name)) or get_next_url(request.GET, field_name=field_name) if good_next_url(request, next_url): + if replace: + for key, value in replace.items(): + next_url = next_url.replace(key, urlparse.quote(value)) return next_url return default -- 2.20.1