Patchwork D1112: hgweb: fix decodevaluefromheaders to always return a bytes value

login
register
mail settings
Submitter phabricator
Date Oct. 16, 2017, 1:51 p.m.
Message ID <differential-rev-PHID-DREV-anp7rsznd2vemwdxa66d-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/24992/
State Superseded
Headers show

Comments

phabricator - Oct. 16, 2017, 1:51 p.m.
durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  That's more in line with what we want, and we know it's ASCII data
  since that's all HTTP technically allows in headers anyway.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/hgweb/protocol.py

CHANGE DETAILS




To: durin42, #hg-reviewers
Cc: mercurial-devel
phabricator - Oct. 16, 2017, 3:07 p.m.
yuja added a comment.


  Perhaps bytesurl()/strurl() should be renamed to e.g. asciibytes()/asciistr()
  since we've started using them everywhere non-ascii character must be rejected.

REPOSITORY
  rHG Mercurial

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

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

Patch

diff --git a/mercurial/hgweb/protocol.py b/mercurial/hgweb/protocol.py
--- a/mercurial/hgweb/protocol.py
+++ b/mercurial/hgweb/protocol.py
@@ -30,15 +30,18 @@ 
 HGERRTYPE = 'application/hg-error'
 
 def decodevaluefromheaders(req, headerprefix):
-    """Decode a long value from multiple HTTP request headers."""
+    """Decode a long value from multiple HTTP request headers.
+
+    Returns the value as a bytes, not a str.
+    """
     chunks = []
     i = 1
+    prefix = headerprefix.upper().replace(r'-', r'_')
     while True:
-        v = req.env.get('HTTP_%s_%d' % (
-            headerprefix.upper().replace('-', '_'), i))
+        v = req.env.get(r'HTTP_%s_%d' % (prefix, i))
         if v is None:
             break
-        chunks.append(v)
+        chunks.append(pycompat.bytesurl(v))
         i += 1
 
     return ''.join(chunks)