summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclIO.c4
-rw-r--r--tests/io.test24
2 files changed, 27 insertions, 1 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index 4a88f52..7e475cc 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -4616,7 +4616,7 @@ Tcl_GetsObj(
if (GotFlag(statePtr, CHANNEL_ENCODING_ERROR)) {
UpdateInterest(chanPtr);
- ResetFlag(statePtr, CHANNEL_ENCODING_ERROR);
+ ResetFlag(statePtr, CHANNEL_EOF|CHANNEL_BLOCKED);
Tcl_SetErrno(EILSEQ);
return TCL_INDEX_NONE;
}
@@ -5941,6 +5941,7 @@ DoReadChars(
int factor = UTF_EXPANSION_FACTOR;
if (GotFlag(statePtr, CHANNEL_ENCODING_ERROR)) {
+ ResetFlag(statePtr, CHANNEL_EOF|CHANNEL_STICKY_EOF|CHANNEL_BLOCKED);
/* TODO: We don't need this call? */
UpdateInterest(chanPtr);
Tcl_SetErrno(EILSEQ);
@@ -6117,6 +6118,7 @@ finish:
* succesfully red before the error. Return an error so that callers
* like [read] can also return an error.
*/
+ ResetFlag(statePtr, CHANNEL_EOF|CHANNEL_ENCODING_ERROR);
Tcl_SetErrno(EILSEQ);
copied = -1;
}
diff --git a/tests/io.test b/tests/io.test
index f1966c7..764c776 100644
--- a/tests/io.test
+++ b/tests/io.test
@@ -9322,6 +9322,30 @@ test io-75.8 {invalid utf-8 encoding eof handling (-profile strict)} -setup {
removeFile io-75.8
} -result {41 1 {}}
+test io-75.8.eoflater {invalid utf-8 encoding eof handling (-profile strict)} -setup {
+ set res {}
+ set fn [makeFile {} io-75.8]
+ set f [open $fn w+]
+ fconfigure $f -encoding binary
+ # \x81 is invalid in utf-8. -eofchar is not detected, because it comes later.
+ puts -nonewline $f A\x81\x1A
+ flush $f
+ seek $f 0
+ fconfigure $f -encoding utf-8 -buffering none -eofchar \x1A \
+ -translation lf -profile strict
+} -body {
+ after 1
+ set status [catch {read $f} cres copts]
+ lappend res $status
+ lappend res [eof $f]
+ chan configure $f -encoding iso8859-1
+ lappend res [read $f]
+ close $f
+ set res
+} -cleanup {
+ removeFile io-75.8
+} -result "1 0 \x81"
+
test io-75.9 {unrepresentable character write passes and is replaced by ?} -setup {
set fn [makeFile {} io-75.9]
set f [open $fn w+]