Patchwork D2660: hgweb: convert req.form to bytes for all keys and values

login
register
mail settings
Submitter phabricator
Date March 4, 2018, 7:17 p.m.
Message ID <09bf5adb438902004984eca2efe2166a@localhost.localdomain>
Download mbox | patch
Permalink /patch/28964/
State Not Applicable
Headers show

Comments

phabricator - March 4, 2018, 7:17 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG2442927cdd96: hgweb: convert req.form to bytes for all keys and values (authored by durin42, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2660?vs=6579&id=6588

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

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

CHANGE DETAILS




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

Patch

diff --git a/mercurial/wireprotoserver.py b/mercurial/wireprotoserver.py
--- a/mercurial/wireprotoserver.py
+++ b/mercurial/wireprotoserver.py
@@ -159,10 +159,10 @@ 
     # HTTP version 1 wire protocol requests are denoted by a "cmd" query
     # string parameter. If it isn't present, this isn't a wire protocol
     # request.
-    if r'cmd' not in req.form:
+    if 'cmd' not in req.form:
         return None
 
-    cmd = pycompat.sysbytes(req.form[r'cmd'][0])
+    cmd = req.form['cmd'][0]
 
     # The "cmd" request parameter is used by both the wire protocol and hgweb.
     # While not all wire protocol commands are available for all transports,
diff --git a/mercurial/hgweb/request.py b/mercurial/hgweb/request.py
--- a/mercurial/hgweb/request.py
+++ b/mercurial/hgweb/request.py
@@ -48,9 +48,11 @@ 
                 form[name] = value
             del form[k]
     # And strip the values
+    bytesform = {}
     for k, v in form.iteritems():
-        form[k] = [i.strip() for i in v]
-    return form
+        bytesform[pycompat.bytesurl(k)] = [
+            pycompat.bytesurl(i.strip()) for i in v]
+    return bytesform
 
 class wsgirequest(object):
     """Higher-level API for a WSGI request.
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
@@ -377,16 +377,16 @@ 
         # translate user-visible url structure to internal structure
 
         args = query.split('/', 2)
-        if r'cmd' not in req.form and args and args[0]:
+        if 'cmd' not in req.form and args and args[0]:
             cmd = args.pop(0)
             style = cmd.rfind('-')
             if style != -1:
                 req.form['style'] = [cmd[:style]]
                 cmd = cmd[style + 1:]
 
             # avoid accepting e.g. style parameter as command
             if util.safehasattr(webcommands, cmd):
-                req.form[r'cmd'] = [cmd]
+                req.form['cmd'] = [cmd]
 
             if cmd == 'static':
                 req.form['file'] = ['/'.join(args)]
@@ -409,7 +409,7 @@ 
                         req.form['node'] = [fn[:-len(ext)]]
                         req.form['type'] = [type_]
         else:
-            cmd = pycompat.sysbytes(req.form.get(r'cmd', [r''])[0])
+            cmd = req.form.get('cmd', [''])[0]
 
         # process the web interface request
 
@@ -423,17 +423,17 @@ 
                 self.check_perm(rctx, req, None)
 
             if cmd == '':
-                req.form[r'cmd'] = [tmpl.cache['default']]
-                cmd = req.form[r'cmd'][0]
+                req.form['cmd'] = [tmpl.cache['default']]
+                cmd = req.form['cmd'][0]
 
             # Don't enable caching if using a CSP nonce because then it wouldn't
             # be a nonce.
             if rctx.configbool('web', 'cache') and not rctx.nonce:
                 caching(self, req) # sets ETag header or raises NOT_MODIFIED
             if cmd not in webcommands.__all__:
                 msg = 'no such method: %s' % cmd
                 raise ErrorResponse(HTTP_BAD_REQUEST, msg)
-            elif cmd == 'file' and r'raw' in req.form.get(r'style', []):
+            elif cmd == 'file' and 'raw' in req.form.get('style', []):
                 rctx.ctype = ctype
                 content = webcommands.rawfile(rctx, req, tmpl)
             else: