Tcl Source Code

View Ticket
Login
2023-04-14
09:33 New ticket [382e6c509c] read loses data under strict encoding. artifact: c1ac2eced9 user: pooryorick

Ticket UUID: 382e6c509c7c0355f3e362ab16b8706339b98cd7
Title: [read] loses data under strict encoding
Type: Bug Created on: 2023-04-14 09:33:18
Submitter: pooryorick Assigned to: nobody
Subsystem: - New Builtin Commands Severity: Important
Priority: 5 Medium Last modified: 2023-04-14 09:33:18
Status: Open Closed by: nobody
Resolution: None Closed on:
Version:
Description:

In the following script, the sequence \xc0\x40 is invalid for utf-8, and read produces an error. When the profile is changed to "replace", read should then produce AB..., but instead it loses AB and produces characters starting at the invalid sequence.

set chan [file tempfile]
chan configure $chan -translation binary
# This is not valid UTF-8
puts $chan helloAB\xc0\x40CD\nEFG
flush $chan
seek $chan 0

chan configure $chan -encoding utf-8 -profile strict
set data [read $chan 5]; #-> hello
puts $data
catch {read $chan 5} res ;#-> error message
puts $res
chan configure $chan -profile replace
set data [read $chan 5] ;#-> does not start with "AB"
puts $data