Patchwork D2739: hgweb: use parsed request to construct query parameters

login
register
mail settings
Submitter phabricator
Date March 9, 2018, 7:30 p.m.
Message ID <6c0f9730031556769d8a76638c2b5877@localhost.localdomain>
Download mbox | patch
Permalink /patch/29196/
State Not Applicable
Headers show

Comments

phabricator - March 9, 2018, 7:30 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG0c1de2e87c6e: hgweb: use parsed request to construct query parameters (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2739?vs=6745&id=6783

REVISION DETAIL
  https://phab.mercurial-scm.org/D2739

AFFECTED FILES
  mercurial/hgweb/hgweb_mod.py
  mercurial/hgweb/request.py

CHANGE DETAILS




To: indygreg, #hg-reviewers, durin42
Cc: mercurial-devel

Patch

diff --git a/mercurial/hgweb/request.py b/mercurial/hgweb/request.py
--- a/mercurial/hgweb/request.py
+++ b/mercurial/hgweb/request.py
@@ -76,6 +76,9 @@ 
     dispatchparts = attr.ib()
     # URL path component (no query string) used for dispatch.
     dispatchpath = attr.ib()
+    # Whether there is a path component to this request. This can be true
+    # when ``dispatchpath`` is empty due to REPO_NAME muckery.
+    havepathinfo = attr.ib()
     # Raw query string (part after "?" in URL).
     querystring = attr.ib()
     # List of 2-tuples of query string arguments.
@@ -188,6 +191,7 @@ 
                          advertisedbaseurl=advertisedbaseurl,
                          apppath=apppath,
                          dispatchparts=dispatchparts, dispatchpath=dispatchpath,
+                         havepathinfo='PATH_INFO' in env,
                          querystring=querystring,
                          querystringlist=querystringlist,
                          querystringdict=querystringdict)
diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py
+++ b/mercurial/hgweb/hgweb_mod.py
@@ -318,15 +318,10 @@ 
                                if h[0] != 'Content-Security-Policy']
             wsgireq.headers.append(('Content-Security-Policy', rctx.csp))
 
-        if r'PATH_INFO' in wsgireq.env:
-            parts = wsgireq.env[r'PATH_INFO'].strip(r'/').split(r'/')
-            repo_parts = wsgireq.env.get(r'REPO_NAME', r'').split(r'/')
-            if parts[:len(repo_parts)] == repo_parts:
-                parts = parts[len(repo_parts):]
-            query = r'/'.join(parts)
+        if req.havepathinfo:
+            query = req.dispatchpath
         else:
-            query = wsgireq.env[r'QUERY_STRING'].partition(r'&')[0]
-            query = query.partition(r';')[0]
+            query = req.querystring.partition('&')[0].partition(';')[0]
 
         # Route it to a wire protocol handler if it looks like a wire protocol
         # request.
@@ -344,7 +339,7 @@ 
 
         # translate user-visible url structure to internal structure
 
-        args = query.split(r'/', 2)
+        args = query.split('/', 2)
         if 'cmd' not in wsgireq.form and args and args[0]:
             cmd = args.pop(0)
             style = cmd.rfind('-')