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.
This commit is contained in:
Benjamin Dauvergne 2019-04-10 12:10:34 +02:00
parent 16aa682aa1
commit bddada5acd
1 changed files with 3 additions and 0 deletions

View File

@ -908,6 +908,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