diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-12-09 14:53:25 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-12-09 14:53:25 (GMT) |
commit | ae31cee4ae595cd1a16f50df82add275c41d8cde (patch) | |
tree | 49231bc14c384d4394dd7bd6e03735d8608b09d1 /tests | |
parent | 768fa22c43bfd6228f6e09e81dfebed70c1a9244 (diff) | |
download | tcl-ae31cee4ae595cd1a16f50df82add275c41d8cde.zip tcl-ae31cee4ae595cd1a16f50df82add275c41d8cde.tar.gz tcl-ae31cee4ae595cd1a16f50df82add275c41d8cde.tar.bz2 |
Add 2 unit-tests, for the 2 cornercases mentioned in the TIP. This shows that the fix works as expected
Diffstat (limited to 'tests')
-rw-r--r-- | tests/io.test | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/io.test b/tests/io.test index c58bbce..d4839f5 100644 --- a/tests/io.test +++ b/tests/io.test @@ -9065,6 +9065,46 @@ test io-75.6 {invalid utf-8 encoding read is not ignored (-strictencoding 1)} -s removeFile io-75.6 } -match glob -result {41 1 {error reading "*": illegal byte sequence}} +test io-75.7 {invalid utf-8 encoding eof handling (-strictencoding 1)} -setup { + set fn [makeFile {} io-75.7] + 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 -strictencoding 1 +} -body { + set d [read $f] + binary scan $d H* hd + lappend hd [eof $f] + lappend hd [catch {read $f} msg] + close $f + lappend hd $msg +} -cleanup { + removeFile io-75.6 +} -match glob -result {41 0 1 {error reading "*": illegal byte sequence}} + +test io-75.8 {invalid utf-8 encoding eof handling (-strictencoding 1)} -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. + puts -nonewline $f "A\x1A\x81" + flush $f + seek $f 0 + fconfigure $f -encoding utf-8 -buffering none -eofchar \x1A -translation lf -strictencoding 1 +} -body { + set d [read $f] + binary scan $d H* hd + lappend hd [eof $f] + lappend hd [read $f] + close $f + set hd +} -cleanup { + removeFile io-75.6 +} -result {41 1 {}} + # ### ### ### ######### ######### ######### |