diff options
| author | pooryorick <com.digitalsmarties@pooryorick.com> | 2023-04-14 07:21:48 (GMT) |
|---|---|---|
| committer | pooryorick <com.digitalsmarties@pooryorick.com> | 2023-04-14 07:21:48 (GMT) |
| commit | d3bb4906d1397f0b5adbeb1da10ce5f6c60a8c1e (patch) | |
| tree | d23852e3e0698f2db488723ac5c4fcf3056a0e5a | |
| parent | f7c3a988274b5e8026bf4836028bfd6831e6a615 (diff) | |
| download | tcl-d3bb4906d1397f0b5adbeb1da10ce5f6c60a8c1e.zip tcl-d3bb4906d1397f0b5adbeb1da10ce5f6c60a8c1e.tar.gz tcl-d3bb4906d1397f0b5adbeb1da10ce5f6c60a8c1e.tar.bz2 | |
Fix for [0cd1ae596e709259], under strict encoding, [gets] returns an error even
though a complete line is available.
| -rw-r--r-- | generic/tclIO.c | 3 | ||||
| -rw-r--r-- | tests/io.test | 70 |
2 files changed, 57 insertions, 16 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c index a1c13ac..aa82f89 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -4997,8 +4997,7 @@ Tcl_GetsObj( } UpdateInterest(chanPtr); TclChannelRelease((Tcl_Channel)chanPtr); - if (GotFlag(statePtr, CHANNEL_ENCODING_ERROR) && - (copiedTotal == 0 || !GotFlag(statePtr, CHANNEL_NONBLOCKING))) { + if (GotFlag(statePtr, CHANNEL_ENCODING_ERROR) && gs.bytesWrote == 0) { Tcl_SetErrno(EILSEQ); copiedTotal = -1; } diff --git a/tests/io.test b/tests/io.test index ae87a79..f0de5b2 100644 --- a/tests/io.test +++ b/tests/io.test @@ -9270,7 +9270,8 @@ test io-75.6 {invalid utf-8 encoding, gets is not ignored (-profile strict)} -se puts -nonewline $f A\x81 flush $f seek $f 0 - fconfigure $f -encoding utf-8 -buffering none -eofchar "" -translation lf -profile strict + fconfigure $f -encoding utf-8 -buffering none -eofchar {} \ + -translation lf -profile strict } -body { gets $f } -cleanup { @@ -9279,7 +9280,9 @@ test io-75.6 {invalid utf-8 encoding, gets is not ignored (-profile strict)} -se } -match glob -returnCodes 1 -result {error reading "file*":\ invalid or incomplete multibyte or wide character} -test io-75.7 {invalid utf-8 encoding gets is not ignored (-profile strict)} -setup { +test io-75.7 { + invalid utf-8 encoding gets is not ignored (-profile strict) +} -setup { set fn [makeFile {} io-75.7] set f [open $fn w+] fconfigure $f -encoding binary @@ -9287,7 +9290,8 @@ test io-75.7 {invalid utf-8 encoding gets is not ignored (-profile strict)} -set puts -nonewline $f A\x81 flush $f seek $f 0 - fconfigure $f -encoding utf-8 -buffering none -eofchar "" -translation lf -profile strict + fconfigure $f -encoding utf-8 -buffering none -eofchar {} -translation lf \ + -profile strict } -body { read $f } -cleanup { @@ -9300,11 +9304,13 @@ test io-75.8 {invalid utf-8 encoding eof handling (-profile strict)} -setup { set fn [makeFile {} io-75.8] set f [open $fn w+] fconfigure $f -encoding binary - # \x81 is invalid in utf-8, but since \x1A comes first, -eofchar takes precedence. + # \x81 is invalid in utf-8, but since \x1A comes first, -eofchar takes + # precedence. puts -nonewline $f A\x1A\x81 flush $f seek $f 0 - fconfigure $f -encoding utf-8 -buffering none -eofchar \x1A -translation lf -profile strict + fconfigure $f -encoding utf-8 -buffering none -eofchar \x1A \ + -translation lf -profile strict } -body { set d [read $f] binary scan $d H* hd @@ -9328,7 +9334,8 @@ test io-75.9 {unrepresentable character write passes and is replaced by ?} -setu } -cleanup { close $f removeFile io-75.9 -} -match glob -result [list {A} {error writing "*": invalid or incomplete multibyte or wide character}] +} -match glob -result [list {A} {error writing "*":\ + invalid or incomplete multibyte or wide character}] test io-75.10 { incomplete multibyte encoding read is not ignored because "binary" sets @@ -9372,7 +9379,8 @@ test io-75.11 {shiftjis encoding error read results in raw bytes} -setup { puts -nonewline $f A\x81\xFFA flush $f seek $f 0 - fconfigure $f -encoding shiftjis -blocking 0 -eofchar "" -translation lf -profile strict + fconfigure $f -encoding shiftjis -blocking 0 -eofchar {} -translation lf \ + -profile strict } -body { set d [read $f] binary scan $d H* hd @@ -9395,7 +9403,7 @@ test io-75.12 { puts -nonewline $f A\x81 flush $f seek $f 0 - fconfigure $f -encoding utf-8 -buffering none -eofchar "" -translation lf + fconfigure $f -encoding utf-8 -buffering none -eofchar {} -translation lf } -body { catch {read $f} errmsg lappend res $errmsg @@ -9423,7 +9431,8 @@ test io-75.13 { puts -nonewline $f A\x81 flush $f seek $f 0 - fconfigure $f -encoding utf-8 -blocking 0 -eofchar "" -translation lf -profile strict + fconfigure $f -encoding utf-8 -blocking 0 -eofchar {} -translation lf \ + -profile strict } -body { set d [read $f] binary scan $d H* hd @@ -9432,7 +9441,36 @@ test io-75.13 { } -cleanup { close $f removeFile io-75.13 -} -match glob -result {41 1 {error reading "file*": invalid or incomplete multibyte or wide character}} +} -match glob -result {41 1 {error reading "file*":\ + invalid or incomplete multibyte or wide character}} + +test io-75.14 { + [gets] succesfully returns lines prior to error + + invalid utf-8 encoding [gets] continues in non-strict mode after error +} -setup { + set fn [makeFile {} io-75.14] + set f [open $fn w+] + fconfigure $f -encoding binary + # \xc0 is invalid in utf-8 + puts -nonewline $f a\nb\xc0\nc\n + flush $f + seek $f 0 + fconfigure $f -encoding utf-8 -buffering none -eofchar {} \ + -translation lf -profile strict +} -body { + lappend res [gets $f] + set status [catch {gets $f} cres copts] + lappend res $status $cres + chan configure $f -profile tcl8 + lappend res [gets $f] + lappend res [gets $f] + close $f + return $res +} -cleanup { + removeFile io-75.14 +} -match glob -result {a 1 {error reading "*":\ + invalid or incomplete multibyte or wide character} bÀ c} # ### ### ### ######### ######### ######### @@ -9487,7 +9525,8 @@ test io-76.4 {channel mode dropping} -setup { } -returnCodes error -cleanup { close $f removeFile dummy -} -match glob -result {Tcl_RemoveChannelMode error: Bad mode, would make channel inacessible. Channel: "*"} +} -match glob -result {Tcl_RemoveChannelMode error:\ + Bad mode, would make channel inacessible. Channel: "*"} test io-76.5 {channel mode dropping} -setup { set datafile [makeFile {some characters} dummy] @@ -9508,7 +9547,8 @@ test io-76.6 {channel mode dropping} -setup { } -returnCodes error -cleanup { close $f removeFile dummy -} -match glob -result {Tcl_RemoveChannelMode error: Bad mode, would make channel inacessible. Channel: "*"} +} -match glob -result {Tcl_RemoveChannelMode error:\ + Bad mode, would make channel inacessible. Channel: "*"} test io-76.7 {channel mode dropping} -setup { set datafile [makeFile {some characters} dummy] @@ -9541,7 +9581,8 @@ test io-76.9 {channel mode dropping} -setup { } -returnCodes error -cleanup { close $f removeFile dummy -} -match glob -result {Tcl_RemoveChannelMode error: Bad mode, would make channel inacessible. Channel: "*"} +} -match glob -result {Tcl_RemoveChannelMode error: + Bad mode, would make channel inacessible. Channel: "*"} test io-76.10 {channel mode dropping} -setup { set datafile [makeFile {some characters} dummy] @@ -9552,7 +9593,8 @@ test io-76.10 {channel mode dropping} -setup { } -returnCodes error -cleanup { close $f removeFile dummy -} -match glob -result {Tcl_RemoveChannelMode error: Bad mode, would make channel inacessible. Channel: "*"} +} -match glob -result {Tcl_RemoveChannelMode error:\ + Bad mode, would make channel inacessible. Channel: "*"} # cleanup foreach file [list fooBar longfile script script2 output test1 pipe my_script \ |
