From 0927e6c7190bbc2391b125530d8976d7342dbabe Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Tue, 5 Dec 2023 16:57:32 +0000 Subject: Also ensure no encoding exceptions raised when reading pipe stderr --- tests/exec.test | 15 ++++++++++++++- unix/tclUnixPipe.c | 2 ++ win/tclWinPipe.c | 4 +++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/exec.test b/tests/exec.test index 7f40a38..4f7a1a8 100644 --- a/tests/exec.test +++ b/tests/exec.test @@ -714,7 +714,7 @@ test exec-20.1 {exec .CMD file} -constraints {win} -body { } -result "\"Testing exec-20.1\"" # Test with encoding mismatches (Bug 0f1ddc0df7fb7) -test exec-21.1 {exec encoding mismatch} -setup { +test exec-21.1 {exec encoding mismatch on stdout} -setup { set path(script) [makeFile { fconfigure stdout -translation binary puts a\xe9b @@ -727,6 +727,19 @@ test exec-21.1 {exec encoding mismatch} -setup { } -body { exec [info nameofexecutable] $path(script) } -result a\uFFFDb +test exec-21.2 {exec encoding mismatch on stderr} -setup { + set path(script) [makeFile { + fconfigure stderr -translation binary + puts stderr a\xe9b + } script] + set enc [encoding system] + encoding system utf-8 +} -cleanup { + removeFile $path(script) + encoding system $enc +} -body { + list [catch {exec [info nameofexecutable] $path(script)} r] $r +} -result [list 1 a\uFFFDb] # ---------------------------------------------------------------------- diff --git a/unix/tclUnixPipe.c b/unix/tclUnixPipe.c index a889f1d..f1e3fb8 100644 --- a/unix/tclUnixPipe.c +++ b/unix/tclUnixPipe.c @@ -1102,6 +1102,8 @@ PipeClose2Proc( errChan = Tcl_MakeFileChannel( INT2PTR(GetFd(pipePtr->errorFile)), TCL_READABLE); + /* Error channels should raise encoding errors */ + Tcl_SetChannelOption(NULL, errChan, "-profile", "replace"); } else { errChan = NULL; } diff --git a/win/tclWinPipe.c b/win/tclWinPipe.c index 600c146..5a18ee3 100644 --- a/win/tclWinPipe.c +++ b/win/tclWinPipe.c @@ -2123,7 +2123,9 @@ PipeClose2Proc( errChan = Tcl_MakeFileChannel((void *) filePtr->handle, TCL_READABLE); Tcl_Free(filePtr); - } else { + Tcl_SetChannelOption(NULL, errChan, "-profile", "replace"); + } + else { errChan = NULL; } -- cgit v0.12