Mercurial > public > mercurial-scm > hg-stable
diff tests/test-wsgirequest.py @ 44825:2632c1ed8f34 stable
hgweb: encode WSGI environment like OS environment
Previously, the WSGI environment keys and values were encoded using latin-1.
This resulted in a crash if a WSGI environment key or value could not be encoded
using latin-1.
On Unix, the OS environment is byte-based. Therefore we should do the reverse of
what Python does for os.environ.
On Windows, there?s no native byte-based OS environment. Therefore we should do
the same as what mercurial.encoding does with the OS environment.
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Thu, 25 Jun 2020 03:46:07 +0200 |
parents | 9f70512ae2cf |
children | 89a2afe31e82 |
line wrap: on
line diff
--- a/tests/test-wsgirequest.py Thu Jun 25 03:10:13 2020 +0200 +++ b/tests/test-wsgirequest.py Thu Jun 25 03:46:07 2020 +0200 @@ -3,7 +3,7 @@ import unittest from mercurial.hgweb import request as requestmod -from mercurial import error +from mercurial import error, pycompat DEFAULT_ENV = { 'REQUEST_METHOD': 'GET', @@ -432,6 +432,18 @@ self.assertEqual(r.dispatchpath, b'path1/path2') self.assertEqual(r.reponame, b'repo') + def testenvencoding(self): + if pycompat.iswindows: + # On Windows, we can't generally know which non-ASCII characters + # are supported. + r = parse(DEFAULT_ENV, extra={'foo': 'bar'}) + self.assertEqual(r.rawenv[b'foo'], b'bar') + else: + # Unix is byte-based. Therefore we test all possible bytes. + b = b''.join(pycompat.bytechr(i) for i in range(256)) + r = parse(DEFAULT_ENV, extra={'foo': pycompat.fsdecode(b)}) + self.assertEqual(r.rawenv[b'foo'], b) + if __name__ == '__main__': import silenttestrunner