Skip to content

Commit bc4ced9

Browse files
committed
Fix for [eabcbd08274f2d22], [read] error persists on channel with strict
encoding after encoding is changed to binary.
1 parent 416b889 commit bc4ced9

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

generic/tclIO.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4616,7 +4616,7 @@ Tcl_GetsObj(
46164616

46174617
if (GotFlag(statePtr, CHANNEL_ENCODING_ERROR)) {
46184618
UpdateInterest(chanPtr);
4619-
ResetFlag(statePtr, CHANNEL_ENCODING_ERROR);
4619+
ResetFlag(statePtr, CHANNEL_EOF|CHANNEL_BLOCKED);
46204620
Tcl_SetErrno(EILSEQ);
46214621
return TCL_INDEX_NONE;
46224622
}
@@ -5941,6 +5941,7 @@ DoReadChars(
59415941
int factor = UTF_EXPANSION_FACTOR;
59425942

59435943
if (GotFlag(statePtr, CHANNEL_ENCODING_ERROR)) {
5944+
ResetFlag(statePtr, CHANNEL_EOF|CHANNEL_STICKY_EOF|CHANNEL_BLOCKED);
59445945
/* TODO: We don't need this call? */
59455946
UpdateInterest(chanPtr);
59465947
Tcl_SetErrno(EILSEQ);
@@ -6117,6 +6118,7 @@ DoReadChars(
61176118
* succesfully red before the error. Return an error so that callers
61186119
* like [read] can also return an error.
61196120
*/
6121+
ResetFlag(statePtr, CHANNEL_EOF|CHANNEL_ENCODING_ERROR);
61206122
Tcl_SetErrno(EILSEQ);
61216123
copied = -1;
61226124
}

tests/io.test

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9322,6 +9322,30 @@ test io-75.8 {invalid utf-8 encoding eof handling (-profile strict)} -setup {
93229322
removeFile io-75.8
93239323
} -result {41 1 {}}
93249324

9325+
test io-75.8.eoflater {invalid utf-8 encoding eof handling (-profile strict)} -setup {
9326+
set res {}
9327+
set fn [makeFile {} io-75.8]
9328+
set f [open $fn w+]
9329+
fconfigure $f -encoding binary
9330+
# \x81 is invalid in utf-8. -eofchar is not detected, because it comes later.
9331+
puts -nonewline $f A\x81\x1A
9332+
flush $f
9333+
seek $f 0
9334+
fconfigure $f -encoding utf-8 -buffering none -eofchar \x1A \
9335+
-translation lf -profile strict
9336+
} -body {
9337+
after 1
9338+
set status [catch {read $f} cres copts]
9339+
lappend res $status
9340+
lappend res [eof $f]
9341+
chan configure $f -encoding iso8859-1
9342+
lappend res [read $f]
9343+
close $f
9344+
set res
9345+
} -cleanup {
9346+
removeFile io-75.8
9347+
} -result "1 0 \x81"
9348+
93259349
test io-75.9 {unrepresentable character write passes and is replaced by ?} -setup {
93269350
set fn [makeFile {} io-75.9]
93279351
set f [open $fn w+]

0 commit comments

Comments
 (0)