Tcl 9: "illegal byte sequence" ?!
Closed / Fixed17a1cb8d6e2a51bde1d5d4a6e55f7d42e408cbbcCreated 4 years agoUpdated 4 years ago
Descriptionplain2022-12-12 23:44:57
With 252e282cd21b (2022-12-12 06:11:22 UTC)
# Create the test data
package require Tcl 9
set fd [open data.txt w+]
fconfigure $fd -encoding utf-8
puts $fd "A\U10FFFFBCDE"
close $fd
# The data is a valid UTF-8 encoded Unicode string
# in the understanding of Tcl.
# Try to read it
package require Tcl 9
set fd [open "data.txt"]
fconfigure $fd -encoding utf-8 -strictencoding 1 -nocomplainencoding 0
set data ""
while {![eof $fd]} {
append data [read $fd]
}
# Not reached with this test data
puts [string length $data]
close $fd
I get:
error reading "file6": illegal byte sequence
while executing
"read $fd"
("while" body line 2)
etc.
Expected behaviour:
Read the data without raising error.
jan.nijtmanswiki2022-12-13 07:59:45
Does [this] clarify the situation?
Referring to ticket [084ab982fe], you asked there:
> Why do we have the fconfigure -strict mode at all?
Apparently, -strict is not the right option for you.
jan.nijtmanswiki2022-12-13 11:47:09
B.T.W. I know that "illegal byte sequence" is not the best error-message we can think of. But that's a limination of the channel code, that we are restricted to POSIX errors. This one is the closest to the truth.
jan.nijtmans Ticket [17a1cb8d6e]: 4 changes
[History diff]2022-12-16 09:42:45
jan.nijtmanswiki2022-12-19 22:21:28
As there seems no interest to check for noncharacters, remove those checks. See [cbaa5e70167db75b]
jan.nijtmanswiki2022-12-20 09:46:27
Branch now merged to core-8-branch and trunk. Closing
Log in (anonymous is fine) to add a comment.