Show More
@@ -12,6 +12,7 b' from __future__ import absolute_import' | |||
|
12 | 12 | |
|
13 | 13 | from ..thirdparty import attr |
|
14 | 14 | from .. import ( |
|
15 | encoding, | |
|
15 | 16 | error, |
|
16 | 17 | pycompat, |
|
17 | 18 | util, |
@@ -162,10 +163,18 b' def parserequestfromenv(env, reponame=No' | |||
|
162 | 163 | # strings on Python 3 must be between \00000-\000FF. We deal with bytes |
|
163 | 164 | # in Mercurial, so mass convert string keys and values to bytes. |
|
164 | 165 | if pycompat.ispy3: |
|
166 | ||
|
165 | 167 | def tobytes(s): |
|
166 | 168 | if not isinstance(s, str): |
|
167 | 169 | return s |
|
168 | return s.encode('latin-1') | |
|
170 | if pycompat.iswindows: | |
|
171 | # This is what mercurial.encoding does for os.environ on | |
|
172 | # Windows. | |
|
173 | return encoding.strtolocal(s) | |
|
174 | else: | |
|
175 | # This is what is documented to be used for os.environ on Unix. | |
|
176 | return pycompat.fsencode(s) | |
|
177 | ||
|
169 | 178 | env = {tobytes(k): tobytes(v) for k, v in pycompat.iteritems(env)} |
|
170 | 179 | |
|
171 | 180 | # Some hosting solutions are emulating hgwebdir, and dispatching directly |
@@ -3,7 +3,7 b' from __future__ import absolute_import, ' | |||
|
3 | 3 | import unittest |
|
4 | 4 | |
|
5 | 5 | from mercurial.hgweb import request as requestmod |
|
6 | from mercurial import error | |
|
6 | from mercurial import error, pycompat | |
|
7 | 7 | |
|
8 | 8 | DEFAULT_ENV = { |
|
9 | 9 | 'REQUEST_METHOD': 'GET', |
@@ -432,6 +432,18 b' class ParseRequestTests(unittest.TestCas' | |||
|
432 | 432 | self.assertEqual(r.dispatchpath, b'path1/path2') |
|
433 | 433 | self.assertEqual(r.reponame, b'repo') |
|
434 | 434 | |
|
435 | def testenvencoding(self): | |
|
436 | if pycompat.iswindows: | |
|
437 | # On Windows, we can't generally know which non-ASCII characters | |
|
438 | # are supported. | |
|
439 | r = parse(DEFAULT_ENV, extra={'foo': 'bar'}) | |
|
440 | self.assertEqual(r.rawenv[b'foo'], b'bar') | |
|
441 | else: | |
|
442 | # Unix is byte-based. Therefore we test all possible bytes. | |
|
443 | b = b''.join(pycompat.bytechr(i) for i in range(256)) | |
|
444 | r = parse(DEFAULT_ENV, extra={'foo': pycompat.fsdecode(b)}) | |
|
445 | self.assertEqual(r.rawenv[b'foo'], b) | |
|
446 | ||
|
435 | 447 | |
|
436 | 448 | if __name__ == '__main__': |
|
437 | 449 | import silenttestrunner |
General Comments 0
You need to be logged in to leave comments.
Login now