summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorapnadkarni <apnmbx-wits@yahoo.com>2023-12-05 13:44:15 (GMT)
committerapnadkarni <apnmbx-wits@yahoo.com>2023-12-05 13:44:15 (GMT)
commit85e3751c642a33bb65b2fa23fb103961fa2436c3 (patch)
tree2a176a31eaa8b673d640a83629cb7829178ba425
parentb844b819dc474968b15fb4c891ded3fd57ea1184 (diff)
downloadtcl-85e3751c642a33bb65b2fa23fb103961fa2436c3.zip
tcl-85e3751c642a33bb65b2fa23fb103961fa2436c3.tar.gz
tcl-85e3751c642a33bb65b2fa23fb103961fa2436c3.tar.bz2
Proposed fix for [0f1ddc0df7].
-rw-r--r--generic/tclIOCmd.c5
-rw-r--r--tests/io.test33
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] {