Skip to content

Commit

Permalink
Forward query string when redirecting from /git-pull/ endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
frankier committed Apr 13, 2023
1 parent af331f8 commit 72f0559
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions nbgitpuller/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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__,
Expand All @@ -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):
"""
Expand Down

0 comments on commit 72f0559

Please sign in to comment.