From 72f0559d60f03f62779efeaca09e77b284930ecf Mon Sep 17 00:00:00 2001 From: Frankie Robertson Date: Sat, 8 Apr 2023 13:12:54 +0300 Subject: [PATCH] Forward query string when redirecting from /git-pull/ endpoint --- nbgitpuller/handlers.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/nbgitpuller/handlers.py b/nbgitpuller/handlers.py index a88f3251..1bf38d63 100644 --- a/nbgitpuller/handlers.py +++ b/nbgitpuller/handlers.py @@ -132,6 +132,20 @@ def pull(): self.git_lock.release() +USED_UI_ARGUMENTS = frozenset(( + 'repo', + 'branch', + 'depth', + 'urlpath', + 'urlPath', + 'subpath', + 'subPath', + 'app', + 'targetpath', + 'targetPath', +)) + + class UIHandler(IPythonHandler): @web.authenticated async def get(self): @@ -160,6 +174,8 @@ async def get(self): else: path = 'tree/' + path + path = self.combine_query_string(path) + self.write( jinja_env.get_template('status.html').render( repo=repo, branch=branch, path=path, depth=depth, targetpath=targetpath, version=__version__, @@ -168,6 +184,22 @@ async def get(self): ) await self.flush() + def combine_query_string(self, targetpath): + """ + This function combines the query string in `targetpath` with all unused + query string parameters passed to this handler. + """ + + from urllib.parse import urlparse, parse_qs, urlencode, urlunparse + target_parsed = urlparse(targetpath) + target_qs = parse_qs(target_parsed.query) + for key in self.request.arguments: + if key in USED_UI_ARGUMENTS or key in target_qs: + continue + target_qs[key] = self.get_argument(key) + targetpath = urlunparse(target_parsed._replace(query=urlencode(target_qs, doseq=True))) + return targetpath + class LegacyGitSyncRedirectHandler(IPythonHandler): """