changeset 50943:32c13716147e

branching: merge with stable
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 08 Sep 2023 20:34:41 +0200
parents 6408777c8fa4 (current diff) 04bfcb416745 (diff)
children 2a7dba8658a7
files mercurial/hgweb/wsgicgi.py
diffstat 2 files changed, 23 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/wsgicgi.py	Wed Sep 06 18:12:27 2023 +0200
+++ b/mercurial/hgweb/wsgicgi.py	Fri Sep 08 20:34:41 2023 +0200
@@ -9,9 +9,7 @@
 # http://www.python.org/dev/peps/pep-0333/#the-server-gateway-side
 
 
-import os
-
-from .. import pycompat
+from .. import encoding, pycompat
 
 from ..utils import procutil
 
@@ -22,7 +20,10 @@
     procutil.setbinary(procutil.stdin)
     procutil.setbinary(procutil.stdout)
 
-    environ = dict(os.environ.items())  # re-exports
+    environ = {
+        k.decode('iso8859-1'): v.decode('iso8859-1')
+        for k, v in encoding.environ.items()
+    }  # re-exports
     environ.setdefault('PATH_INFO', '')
     if environ.get('SERVER_SOFTWARE', '').startswith('Microsoft-IIS'):
         # IIS includes script_name in PATH_INFO
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-wsgicgi.t	Fri Sep 08 20:34:41 2023 +0200
@@ -0,0 +1,18 @@
+  $ hg init test
+  $ cat >hgweb.cgi <<HGWEB
+  > #!$PYTHON
+  > from mercurial import demandimport; demandimport.enable()
+  > from mercurial.hgweb import hgweb
+  > from mercurial.hgweb import wsgicgi
+  > application = hgweb(b"test", b"Empty test repository")
+  > wsgicgi.launch(application)
+  > HGWEB
+  $ chmod 755 hgweb.cgi
+
+Check that non-ASCII bytes roundtrip correctly.
+
+  $ . "$TESTDIR/cgienv"
+  $ PATH_INFO="/rev/$(python -c 'import sys; sys.stdout.buffer.write(b"\xe2\x80\x94")')"; export PATH_INFO
+  $ QUERY_STRING="style=raw"; export QUERY_STRING
+  $ "$PYTHON" ./hgweb.cgi | grep error
+  error: unknown revision '\xe2\x80\x94' (esc)