Skip to content

Commit 6ab561a

Browse files
committed
Updates and slight refactor in fix
1 parent acc5799 commit 6ab561a

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

CHANGES.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
1818
will benefit from `TypeGuard`/`TypeIs`, to produce intellisense similar
1919
to using `isinstance` directly.
2020

21+
From Anthony Siegrist;
22+
- On win32 platform, handle piped process output more robustly. Output encoding
23+
fallback to UTF8 if it is defined at None by the output stream object.
24+
2125
From Mats Wichmann:
2226
- env.Dump() now considers the "key" positional argument to be a varargs
2327
type (zero, one or many). However called, it returns a serialized
@@ -41,9 +45,7 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
4145
Make doc function signature style more consistent - tweaks to AddOption,
4246
DefaultEnvironment and Tool,.
4347

44-
From Anthony Siegrist;
45-
- On win32 platform, handle piped process output more robustly. Output encoding
46-
fallback to UTF8 if it is defined at None by the output stream object.
48+
4749

4850

4951
RELEASE 4.8.0 - Sun, 07 Jul 2024 17:22:20 -0700

SCons/Platform/win32.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ def piped_spawn(sh, escape, cmd, args, env, stdout, stderr):
148148
if not stderrRedirected:
149149
args.append("2>" + tmpFileStderrName)
150150

151+
# Sanitize encoding. None is not a valid encoding.
152+
if stdout.encoding is None:
153+
stdout.encoding = 'utf-8'
154+
if stderr.encoding is None:
155+
stderr.encoding = 'utf-8'
156+
151157
# actually do the spawn
152158
try:
153159
args = [sh, '/C', escape(' '.join(args))]
@@ -167,7 +173,7 @@ def piped_spawn(sh, escape, cmd, args, env, stdout, stderr):
167173
try:
168174
with open(tmpFileStdoutName, "rb") as tmpFileStdout:
169175
output = tmpFileStdout.read()
170-
stdout.write(output.decode(stdout.encoding if stdout.encoding is not None else 'utf-8', "replace"))
176+
stdout.write(output.decode(stdout.encoding, "replace"))
171177
os.remove(tmpFileStdoutName)
172178
except OSError:
173179
pass
@@ -176,7 +182,7 @@ def piped_spawn(sh, escape, cmd, args, env, stdout, stderr):
176182
try:
177183
with open(tmpFileStderrName, "rb") as tmpFileStderr:
178184
errors = tmpFileStderr.read()
179-
stderr.write(errors.decode(stderr.encoding if stderr.encoding is not None else 'utf-8', "replace"))
185+
stderr.write(errors.decode(stderr.encoding, "replace"))
180186
os.remove(tmpFileStderrName)
181187
except OSError:
182188
pass

0 commit comments

Comments
 (0)