summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2023-02-12 01:00:58 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2023-02-12 01:00:58 (GMT)
commitbfaa709c2e5c8d857021cf983e97f1946cff0b06 (patch)
tree5594d69acf2fafdf9d5e2a84355c4a31ead87bad
parentc529405c659f132d217336a626895a13a0ecaef0 (diff)
parent3954b7c2a3da78ea609c42339cf7ed4e62aee30b (diff)
downloadtcl-bfaa709c2e5c8d857021cf983e97f1946cff0b06.zip
tcl-bfaa709c2e5c8d857021cf983e97f1946cff0b06.tar.gz
tcl-bfaa709c2e5c8d857021cf983e97f1946cff0b06.tar.bz2
Merge 8.7
-rw-r--r--generic/tclIO.c8
-rw-r--r--tests/io.test97
2 files changed, 105 insertions, 0 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index 98315db..26d0011 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -9695,12 +9695,20 @@ CopyData(
Tcl_SetErrno(inStatePtr->unreportedError);
inStatePtr->unreportedError = 0;
goto readError;
+ } else if (inStatePtr->flags & CHANNEL_ENCODING_ERROR) {
+ Tcl_SetErrno(EILSEQ);
+ inStatePtr->flags &= ~CHANNEL_ENCODING_ERROR;
+ goto readError;
}
Tcl_GetChannelError(outChan, &msg);
if ((outStatePtr->unreportedError != 0) || (msg != NULL)) {
Tcl_SetErrno(outStatePtr->unreportedError);
outStatePtr->unreportedError = 0;
goto writeError;
+ } else if (outStatePtr->flags & CHANNEL_ENCODING_ERROR) {
+ Tcl_SetErrno(EILSEQ);
+ outStatePtr->flags &= ~CHANNEL_ENCODING_ERROR;
+ goto writeError;
}
if (cmdPtr && (mask == 0)) {
diff --git a/tests/io.test b/tests/io.test
index 919ea8b..fdc9247 100644
--- a/tests/io.test
+++ b/tests/io.test
@@ -7609,6 +7609,103 @@ test io-52.19 {coverage of eofChar handling} {
close $out
file size $path(test2)
} 8
+test io-52.20 {TclCopyChannel & encodings} -setup {
+ set out [open $path(utf8-fcopy.txt) w]
+ fconfigure $out -encoding utf-8 -translation lf
+ puts $out "Á"
+ close $out
+} -constraints {fcopy} -body {
+ # binary to encoding => the input has to be
+ # in utf-8 to make sense to the encoder
+
+ set in [open $path(utf8-fcopy.txt) r]
+ set out [open $path(kyrillic.txt) w]
+
+ # Using "-encoding ascii" means reading the "Á" gives an error
+ fconfigure $in -encoding ascii -strictencoding 1
+ fconfigure $out -encoding koi8-r -translation lf
+
+ fcopy $in $out
+} -cleanup {
+ close $in
+ close $out
+} -returnCodes 1 -match glob -result {error reading "file*": illegal byte sequence}
+test io-52.21 {TclCopyChannel & encodings} -setup {
+ set out [open $path(utf8-fcopy.txt) w]
+ fconfigure $out -encoding utf-8 -translation lf
+ puts $out "Á"
+ close $out
+} -constraints {fcopy} -body {
+ # binary to encoding => the input has to be
+ # in utf-8 to make sense to the encoder
+
+ set in [open $path(utf8-fcopy.txt) r]
+ set out [open $path(kyrillic.txt) w]
+
+ # Using "-encoding ascii" means writing the "Á" gives an error
+ fconfigure $in -encoding utf-8
+ fconfigure $out -encoding ascii -translation lf -strictencoding 1
+
+ fcopy $in $out
+} -cleanup {
+ close $in
+ close $out
+} -returnCodes 1 -match glob -result {error writing "file*": illegal byte sequence}
+test io-52.22 {TclCopyChannel & encodings} -setup {
+ set out [open $path(utf8-fcopy.txt) w]
+ fconfigure $out -encoding utf-8 -translation lf
+ puts $out "Á"
+ close $out
+} -constraints {fcopy} -body {
+ # binary to encoding => the input has to be
+ # in utf-8 to make sense to the encoder
+
+ set in [open $path(utf8-fcopy.txt) r]
+ set out [open $path(kyrillic.txt) w]
+
+ # Using "-encoding ascii" means reading the "Á" gives an error
+ fconfigure $in -encoding ascii -strictencoding 1
+ fconfigure $out -encoding koi8-r -translation lf
+ proc ::xxx args {
+ set ::s0 $args
+ }
+
+ fcopy $in $out -command ::xxx
+ vwait ::s0
+ set ::s0
+} -cleanup {
+ close $in
+ close $out
+ unset ::s0
+} -match glob -result {0 {error reading "file*": illegal byte sequence}}
+test io-52.23 {TclCopyChannel & encodings} -setup {
+ set out [open $path(utf8-fcopy.txt) w]
+ fconfigure $out -encoding utf-8 -translation lf
+ puts $out "Á"
+ close $out
+} -constraints {fcopy} -body {
+ # binary to encoding => the input has to be
+ # in utf-8 to make sense to the encoder
+
+ set in [open $path(utf8-fcopy.txt) r]
+ set out [open $path(kyrillic.txt) w]
+
+ # Using "-encoding ascii" means writing the "Á" gives an error
+ fconfigure $in -encoding utf-8
+ fconfigure $out -encoding ascii -translation lf -strictencoding 1
+ proc ::xxx args {
+ set ::s0 $args
+ }
+
+ fcopy $in $out -command ::xxx
+ vwait ::s0
+ set ::s0
+} -cleanup {
+ close $in
+ close $out
+ unset ::s0
+} -match glob -result {0 {error writing "file*": illegal byte sequence}}
+
test io-53.1 {CopyData} {fcopy} {
file delete $path(test1)