зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1152428 - [mozprocess] Fix UnicodeEncodeError when non-ascii characters are in the environment, r=wlach
MozReview-Commit-ID: 3AG9oLxWexy --HG-- extra : rebase_source : a1f0d66c9434e2129c166181105b55fad43fe716
This commit is contained in:
Родитель
02772181cb
Коммит
c2f03c6447
|
@ -97,16 +97,6 @@ class ProcessHandlerMixin(object):
|
|||
os.setpgid(0, 0)
|
||||
preexec_fn = setpgidfn
|
||||
|
||||
if isinstance(env, dict):
|
||||
tmp_env = {}
|
||||
for k, v in env.iteritems():
|
||||
if isinstance(k, bytes):
|
||||
k = k.decode(sys.getfilesystemencoding() or 'utf-8', 'replace')
|
||||
if isinstance(v, bytes):
|
||||
v = v.decode(sys.getfilesystemencoding() or 'utf-8', 'replace')
|
||||
tmp_env[k] = v
|
||||
env = tmp_env
|
||||
|
||||
try:
|
||||
subprocess.Popen.__init__(self, args, bufsize, executable,
|
||||
stdin, stdout, stderr,
|
||||
|
|
|
@ -34,7 +34,9 @@
|
|||
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import sys
|
||||
|
||||
from ctypes import c_void_p, POINTER, sizeof, Structure, windll, WinError, WINFUNCTYPE, c_ulong
|
||||
from ctypes.wintypes import BOOL, BYTE, DWORD, HANDLE, LPCWSTR, LPWSTR, UINT, WORD
|
||||
|
@ -137,12 +139,18 @@ class EnvironmentBlock:
|
|||
"""An object which can be passed as the lpEnv parameter of CreateProcess.
|
||||
It is initialized with a dictionary."""
|
||||
|
||||
def __init__(self, dict):
|
||||
if not dict:
|
||||
def __init__(self, env):
|
||||
if not env:
|
||||
self._as_parameter_ = None
|
||||
else:
|
||||
values = ["%s=%s" % (key, value)
|
||||
for (key, value) in dict.iteritems()]
|
||||
values = []
|
||||
fs_encoding = sys.getfilesystemencoding() or 'mbcs'
|
||||
for k, v in env.iteritems():
|
||||
if isinstance(k, bytes):
|
||||
k = k.decode(fs_encoding, 'replace')
|
||||
if isinstance(v, bytes):
|
||||
v = v.decode(fs_encoding, 'replace')
|
||||
values.append("{}={}".format(k, v))
|
||||
values.append("")
|
||||
self._as_parameter_ = LPCWSTR("\0".join(values))
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
@ -24,5 +25,16 @@ class ProcTestMisc(proctest.ProcTest):
|
|||
|
||||
self.determine_status(p, False, ())
|
||||
|
||||
def test_unicode_in_environment(self):
|
||||
env = {
|
||||
'FOOBAR': 'ʘ',
|
||||
}
|
||||
p = processhandler.ProcessHandler([self.python, self.proclaunch,
|
||||
"process_normal_finish_python.ini"],
|
||||
cwd=here, env=env)
|
||||
# passes if no exceptions are raised
|
||||
p.run()
|
||||
p.wait()
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Загрузка…
Ссылка в новой задаче