diff options
| -rw-r--r-- | generic/tclIOCmd.c | 5 | ||||
| -rw-r--r-- | tests/io.test | 33 |
2 files changed, 38 insertions, 0 deletions
diff --git a/generic/tclIOCmd.c b/generic/tclIOCmd.c index b6fd799..40cf074 100644 --- a/generic/tclIOCmd.c +++ b/generic/tclIOCmd.c @@ -944,6 +944,11 @@ Tcl_ExecObjCmd( return TCL_ERROR; } + /* Bug [0f1ddc0df7] - encoding errors - use replace profile */ + if (Tcl_SetChannelOption(NULL, chan, "-profile", "replace") != TCL_OK) { + return TCL_ERROR; + } + if (background) { /* * Store the list of PIDs from the pipeline in interp's result and diff --git a/tests/io.test b/tests/io.test index 8fb2a99..c11f325 100644 --- a/tests/io.test +++ b/tests/io.test @@ -9824,6 +9824,39 @@ test io-76.10 {channel mode dropping} -setup { } -match glob -result {Tcl_RemoveChannelMode error:\ Bad mode, would make channel inacessible. Channel: "*"} +# Encoding errors on pipeline +# Ensures fix for exec bug [0f1ddc0df7] does not affect open +# It should still fail unless -profile is explicitly set to replace +test io-77.1 {open pipe encoding mismatch} -setup { + set scriptFile [makeFile { + fconfigure stdout -translation binary + puts -nonewline a\xe9b + flush stdout + } script] +} -cleanup { + close $fd + removeFile $scriptFile +} -body { + set fd [open |[list [info nameofexecutable] $scriptFile r+]] + fconfigure $fd -encoding utf-8 + list [catch {read $fd} result opts] [string match {error reading "*": invalid or incomplete multibyte or wide character} $result] [dict get $opts -errorcode] +} -result [list 1 1 {POSIX EILSEQ {invalid or incomplete multibyte or wide character}}] +test io-77.2 {open pipe encoding mismatch - use replace profile} -setup { + set scriptFile [makeFile { + fconfigure stdout -translation binary + puts -nonewline a\xe9b + flush stdout + } script] +} -cleanup { + close $fd + removeFile $scriptFile +} -body { + set fd [open |[list [info nameofexecutable] $scriptFile r+]] + fconfigure $fd -encoding utf-8 -profile replace + read $fd +} -result a\uFFFDb + + # cleanup foreach file [list fooBar longfile script script2 output test1 pipe my_script \ test2 test3 cat stdout kyrillic.txt utf8-fcopy.txt utf8-rp.txt] { |
