Overview
| Artifact ID: | 47fce23ced0126d4e078ab2e885ab54f6ebb351ad646fc5fb189a38d066a2b5a |
|---|---|
| Ticket: | b8f575aa2398b0e44b5a037326b9d75037e2da4a
Tcl 9: eof erroneously flagged with not reported encoding read error |
| User & Date: | jan.nijtmans on 2022-12-09 15:07:56 |
Changes
- icomment:
> Isn't this a bit awkwarded / convoluted? Especially given that most programmers are typically don't expect to have to check [eof] if they want to read the whole data out of a file in one go with [read $fd]. Indeed, in Tcl 8.x, doing a [read $fd] get the whole content of the file (unless using -eofchar, then everything after the eofchar is stripped). That - indeed - should stay in Tcl 9.0. The reason that it succeeds always, is that there is no error-reporting for encoding errors. For utf-8, \x81 is an invalid byte sequence, but it will silently be handled as if it was \xC2\x01, assuming iso-8859-1 in stead of utf-8 as fallback. When -strictencoding is specified, [read] is no longer guaranteed to read the whole file. It will read until EOF, or until the eofchar or until an encoding error is encountered. [eof] can be used to make the distinction, and a further [read] will throw an exception. It's up to the user how to handle this. One possibility would be to change the encoding of the channel, and do another read. So, yes, I think this is how I would expect it to work. In short: If you are not prepared to handle errors, don't use -strictencoding. Thank you for this report and the test-case! Whenever [eof] returns true, any follow-up [read] should return the empty string (or return more data if it became availble in the meantime). That's an assumption from Tcl 8.x that I would like to keep in 9.0. In your example, that was violated, which means that I - indeed - consider this a real bug (which - hopefully - is fixed with this change)
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"