зеркало из 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)
|
os.setpgid(0, 0)
|
||||||
preexec_fn = setpgidfn
|
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:
|
try:
|
||||||
subprocess.Popen.__init__(self, args, bufsize, executable,
|
subprocess.Popen.__init__(self, args, bufsize, executable,
|
||||||
stdin, stdout, stderr,
|
stdin, stdout, stderr,
|
||||||
|
|
|
@ -34,7 +34,9 @@
|
||||||
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||||
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
# 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 import c_void_p, POINTER, sizeof, Structure, windll, WinError, WINFUNCTYPE, c_ulong
|
||||||
from ctypes.wintypes import BOOL, BYTE, DWORD, HANDLE, LPCWSTR, LPWSTR, UINT, WORD
|
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.
|
"""An object which can be passed as the lpEnv parameter of CreateProcess.
|
||||||
It is initialized with a dictionary."""
|
It is initialized with a dictionary."""
|
||||||
|
|
||||||
def __init__(self, dict):
|
def __init__(self, env):
|
||||||
if not dict:
|
if not env:
|
||||||
self._as_parameter_ = None
|
self._as_parameter_ = None
|
||||||
else:
|
else:
|
||||||
values = ["%s=%s" % (key, value)
|
values = []
|
||||||
for (key, value) in dict.iteritems()]
|
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("")
|
values.append("")
|
||||||
self._as_parameter_ = LPCWSTR("\0".join(values))
|
self._as_parameter_ = LPCWSTR("\0".join(values))
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
|
@ -24,5 +25,16 @@ class ProcTestMisc(proctest.ProcTest):
|
||||||
|
|
||||||
self.determine_status(p, False, ())
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Загрузка…
Ссылка в новой задаче