Artifacts Associated With Ticket 4a7397e0b3
Ticket change [f78cf0cc95] (rid 207973) by pointsman on 2022-12-22 13:27:22:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
package require Tcl 9 # Create the test data set fd [open "data.txt" w+] fconfigure $fd -encoding binary # Not valid UTF-8 puts $fd AB\xc0\x40CD\nEFG close $fd set in [open "data.txt"] set out [open "copy.txt" w+] fconfigure $in -encoding utf-8 -strictencoding 1 fconfigure $out -encoding utf-8 -strictencoding 1 fcopy $in $out Again I'm not sure how this is supposed to work but the result did surprise me. The script runs to its end without any error. The created file "copy.txt" is byte indentical with "data.txt". Neither the -strictencoding 1 on the in channel nor the -strictencoding 1 on the out channel seem to do anything, if the channels are used with fcopy. At minimum this should be noted either in the fcopy or the fconfigure documentation (I looked but didn't found something about this case atm). Better, I think, would maybe rasing error on the fcopy. But as written I'm not sure how this is supposed to work.
- foundin initialized to: "Tcl 9, trunk"
- is_private initialized to: "0"
- login: "pointsman"
- priority initialized to: "5 Medium"
- private_contact initialized to: "4ca203a8e925aecdd9419645f936bccf18cd6ea7"
- resolution initialized to: "None"
- severity initialized to: "Important"
- status initialized to: "Open"
- submitter initialized to: "pointsman"
- subsystem initialized to: "25. Channel System"
- title initialized to: "Tcl 9: fcopy with -strictencoding 1 UTF-8 channels"
- type initialized to: "Bug"
Ticket change [00c9748172] (rid 207976) by jan.nijtmans on 2022-12-22 14:42:33:
- icomment:
Looking [https://core.tcl-lang.org/tcl/file?udc=1&ln=9677&ci=tip&name=generic%2FtclIO.c|here], it's quite understandable why this happens. The fcopy code has a variable "sameEncoding", which prevents the encoding/decoding step when both encodings are the same. That's an optimization which doesn't take the new flags into account Changing priority to "Cosmetic". If you like, you can submit a patch removing this variable, but the chance introducing a problem is higher than the chance solving anything practical. More useful (and related): What happens when converting between utf-8 and utf-16 (for example). "fcopy" is not able to throw an exception currently.
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- severity changed to: "Cosmetic"
- icomment:
Ticket change [aaa667d098] (rid 208394) by oehhar on 2023-01-25 19:28:17:
- icomment:
Dear Rolf, Jan, to my understanding, fcopy works as expected. It is documented to pass data verbatim if the encoding matches. That is what happens. Take care, Harald
- login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
- icomment:
Ticket change [b262cebb8f] (rid 208398) by pointsman on 2023-01-26 02:13:34:
- icomment:
I don't read this in the documentation. The only according quote I find is "No conversion is done if both channels are set to encoding “binary” and have matching translations" which seems to me to be something else (binary versus UTF-8 with explicit -strict configured channel). And the argument "encoding matches" is void if the involved channels are fconfigured to, say, UTF-8 and UTF-16. Of course every behaviour could be documented "away" - write what it does in the documentation. But's not necessarily a good solution. If I fconfigure my channel with -strict 1 I clearly said that I want to be informed about encoding errors. You can define that away by documentation. But I think this is wrong. Jan is right, fcopy should throw execption.
- login: "pointsman"
- mimetype: "text/plain"
- icomment:
Ticket change [2b49605281] (rid 208399) by jan.nijtmans on 2023-01-26 07:40:20:
- icomment:
> Jan is right, fcopy should throw execption. If the channel doesn't have -command specified, an exception should be thrown when an encoding error occurs. If -command is specified, the command will be called with 2 arguments Another tweak: according to the documentation: [https://core.tcl-lang.org/tcl/file?name=doc/fcopy.n&ci=f9cdaa50ad760a0c&ln=29-30] That's not 100% correct any more. For Tcl 8.7, it should become: size is in bytes if the input channel is in binary mode, or if the two channels are using the same encoding and -strict is not specified. Otherwise, size is in characters. For Tcl 9.0, it should become: size is in bytes if the input channel is in binary mode, and is in characters otherwise. Agreed?
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [5c9155e8ed] (rid 208400) by oehhar on 2023-01-26 13:28:36:
- icomment:
Sorry, my comment was just plain wrong, sorry for the nois, Harald
- login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
- icomment:
Ticket change [9503628092] (rid 208401) by pointsman on 2023-01-26 15:19:14:
- icomment:
> If the channel doesn't have -command specified, an exception should be thrown > when an encoding error occurs. If -command is specified, the command > will be called with 2 arguments Yes, of course - raise error in case of working not in the background and if working in the background then use the already established error reporting way via second argument to the callback. > Another tweak: according to the documentation: https://core.tcl-lang.org/tcl/file?name=doc/fcopy.n&ci=f9cdaa50ad760a0c&ln=29-30 Just as note: The chan command documentation should be updated according to all fcopy documentation change. > For Tcl 9.0, it should become: size is in bytes if the input channel is in binary mode, and is in characters otherwise. That would be along the lines of how it it is. To be sure: You mean independent of -strict status of the channels? I'm not so sure if this is what is needed in practice (say, copy file from server and the size of the file to expect is given (typically) in bytes in the header) but this is cleary outside the scope of this ticket. So, I guess: Yes, I agree with respect to Tcl 9. For 8.7 the proposed rule would even be more complicated as it alread is: -size is interpreted as bytes for binary channels _and_ if the channels have the same encoding and no -strict 1. But that may be indispensable.
- login: "pointsman"
- mimetype: "text/x-fossil-plain"
- icomment:
Ticket change [450dea01f5] (rid 208662) by jan.nijtmans on 2023-02-10 20:25:16:
- assignee changed to: "jan.nijtmans"
- icomment: "Proposed fix [0f04d39da489dafb|here]"
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- severity changed to: "Important"
- status changed to: "Pending"
Ticket change [fae67b50a6] (rid 208678) by jan.nijtmans on 2023-02-12 01:10:21:
- icomment:
Fixed in [8b772479c3]. More testcases would be welcome, e.g. testing whether the input/output channels after the fcopy have the correct file position: If an exception is thrown, the file position is expected to be exactly on the position where the encoding error occurred. And - in case of an encoding error on input - the characters received so far should be written to the output channel. I think it should work, but this is not thoroughly tested. It's entirely new functionality. Someone willing to help?
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [d5dc3a86bf] (rid 209335) by pooryorick on 2023-02-28 12:06:21:
- icomment:
The proposed fix, [8b772479c3587d91], was moved off core-8-branch because it relies on an unapproved fix for [b8f575aa2398b0e4], which broke the semantics of [read]/[gets]. The current issue should be revisited once a proper fix for the other issue is in place.
- login: "pooryorick"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "None"
- status changed to: "Open"
- icomment:
Ticket change [5da15e9145] (rid 209360) by jan.nijtmans on 2023-02-28 13:43:39:
- closedate changed to: "2460004.07198809"
- closer changed to: "jan.nijtmans"
- icomment:
Fixed again [9c0db3d168636cbd|here]. Testcase io-52.20 should not have been removed. If you really are unable to provide a proper fix, at least it should have been marked "knownBug"! This fix (using an additional flag) is not the most elegant solution, but - since - you (@nathan) are working on a better fix for "read" (I hope), any fix for "read" should not ruin "fcopy" (neither "gets", but that's another ticket). Feel free to remove the ENCODING_FCOPY flags as soon as you no longer need it. But io-52.20 should continue working as-is.
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Closed"