Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 357df60d3d866b5af6ed9fbd65d7eeb8e7287434c91dbfe57950f1660951b301
Ticket: 154ed7ce564a7b4cc39463d643b251969006c247
Tcl 9: [gets] on -strictencoding 1 configured channel
User & Date: jan.nijtmans on 2023-02-23 15:22:41
Changes

  1. icomment:
    From [Ashok's document](https://www.magicsplat.com/tcl9/tcl9unicode.html):
    
    _6.5.2 Channel read state after errors_
    
    Related to the above is the question of the channel state when an exception is raised on a read or gets due to invalid input bytes.
    
    My opinion is that when an exception is raised, the read position should not be changed from the value at the time the read or gets was invoked. This allows the application to then turn off the strict checking (if so desired) and read in the rest of the data. For example,
    
    <pre>
    % set fd [open x.txt r]
    file1de34c88158
    % fconfigure $fd -encoding utf-8 -strictencoding 1
    % gets $fd
    a
    % gets $fd
    error reading "file1de34c88158": illegal byte sequence
    % fconfigure $fd -encoding utf-8 -strictencoding 0
    % gets $fd
    bÀ
    % gets $fd
    c
    </pre>
    
    An alternate suggestion made in the mailing list was to move the read position to the location of the invalid byte and return the characters successfully decoded so far in the error options dictionary. My personal opinion is returning successfully read data in the error options is unnatural and non-idiomatic.
    
  2. login: "jan.nijtmans"
  3. mimetype: "text/x-markdown"