changeset 7763:ca8f597c8fa8

clone_url: use regexp and single pass for variable expansion - avoid nested expansion in case a variable value would contain a variable reference It would probably never be a problem in real life, but just avoid the tech debt of doing it wrong ...
author Mads Kiilerich <mads@kiilerich.com>
date Wed, 31 Jul 2019 02:29:36 +0200
parents 47e11e924cbe
children dbf3c33a516c
files kallithea/lib/utils2.py
diffstat 1 files changed, 2 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/utils2.py	Tue Jul 16 12:10:33 2019 +0200
+++ b/kallithea/lib/utils2.py	Wed Jul 31 02:29:36 2019 +0200
@@ -422,12 +422,10 @@
         'repo': repo_name,
         'repoid': str(repo_id),
     }
-
-    for k, v in args.items():
-        clone_uri_tmpl = clone_uri_tmpl.replace('{%s}' % k, v)
+    url = re.sub('{([^{}]+)}', lambda m: args.get(m.group(1), m.group(0)), clone_uri_tmpl)
 
     # remove leading @ sign if it's present. Case of empty user
-    url_obj = urlobject.URLObject(clone_uri_tmpl)
+    url_obj = urlobject.URLObject(url)
     url = url_obj.with_netloc(url_obj.netloc.lstrip('@'))
 
     return safe_unicode(url)