Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2023-03-24
13:16
Merge trunk c8983a2a94: Fix [154ed7ce56]: Tcl 9: [gets] on -strictencoding 1 configured channel. check-in: 5966973d58 user: pooryorick tags: unchained
2023-03-21
09:17 • Closed ticket [154ed7ce56]: Tcl 9: gets on -strictencoding 1 configured channe... artifact: a8f223b6de user: jan.nijtmans
08:44
Fix [154ed7ce56]: Tcl 9: [gets] on -strictencoding 1 configured channel check-in: c02747a663 user: jan.nijtmans tags: core-8-branch
2023-03-20
22:53
Proposed fix for [154ed7ce56]: Tcl 9: [gets] on -strictencoding 1 configured channel. Extracted fro... closed check-in: a338fcd542 user: jan.nijtmans tags: bug-154ed7ce56
2023-02-23
15:22 • Ticket [154ed7ce56] Tcl 9: gets on -strictencoding 1 configured channel st... artifact: 357df60d3d user: jan.nijtmans
2023-02-18
01:16 • Ticket [154ed7ce56]: 3 changes artifact: 4687b617f5 user: pooryorick
2023-02-17
08:05 • Ticket [b8f575aa23] Tcl 9: eof erroneously flagged with not reported encoding re... artifact: bee454c54f user: pooryorick
2023-02-14
10:43
Fix for [b8f575aa2398b0e4] and [154ed7ce564a7b4c], double-[read]/[gets] problem. Partial-read functi... closed check-in: ecd7aaec80 user: pooryorick tags: py-b8f575aa23-nopartial
2023-02-04
14:10
Fix for [b8f575aa2398b0e4] and [154ed7ce564a7b4c], double-[read]/[gets] problem. Partial-read functi... check-in: 0a74820b6d user: pooryorick tags: py-b8f575aa23-nopartial
2023-02-03
22:15
Fix for [b8f575aa2398b0e4] and [154ed7ce564a7b4c], double-[read]/[gets] problem. Partial-read funct... check-in: 104b05b17c user: pooryorick tags: py-b8f575aa23-nopartial
2023-02-02
22:51
Fix for [b8f575aa2398b0e4] and [154ed7ce564a7b4c], double-[read]/[gets] problem. Partial-read funct... check-in: 11c7f071cb user: pooryorick tags: py-b8f575aa23-nopartial
2023-01-17
22:09 • Ticket [154ed7ce56] Tcl 9: gets on -strictencoding 1 configured channel st... artifact: 393b9c6ea6 user: pooryorick
20:09
Fix for [b8f575aa2398b0e4], and also for [154ed7ce56], Tcl 9: [gets] on -strictencoding 1 configured... closed check-in: 4cdf4836aa user: pooryorick tags: py-b8f575aa23-errorinfo
2023-01-02
23:12
Merge py-b8f575aa23: Fix for [154ed7ce56], Tcl 9: [gets] on -strictencoding 1 configured channel. check-in: 8c5d9bcc6e user: pooryorick tags: py-b8f575aa23
21:10 • Ticket [154ed7ce56] Tcl 9: gets on -strictencoding 1 configured channel st... artifact: a2586325fc user: pooryorick
21:07
Fix for [154ed7ce56], Tcl 9: [gets] on -strictencoding 1 configured channel. check-in: 003c9e1f2e user: pooryorick tags: trunk-encodingdefaultstrict
2022-12-25
00:14 • Ticket [154ed7ce56] Tcl 9: gets on -strictencoding 1 configured channel st... artifact: 27b4573ac7 user: pointsman
2022-12-22
14:45 • Ticket [154ed7ce56]: 3 changes artifact: 4e13af1770 user: jan.nijtmans
13:27 • Ticket [154ed7ce56]: 3 changes artifact: c6bdb92251 user: pointsman
13:15 • New ticket [154ed7ce56]. artifact: 4b2cae1fcf user: pointsman

Tcl 9: [gets] on -strictencoding 1 configured channel

Closed / Fixed154ed7ce564a7b4cc39463d643b251969006c247Created 4 years agoUpdated 4 years ago
Descriptionplain2022-12-22 13:15:31
# Create the data
package require Tcl 9
set fd [open "data.txt" w+]
fconfigure $fd -encoding binary
# This is not valid UTF-8
puts $fd AB\xc0\x40CD\nEFG
close $fd

# Now try to read it with [gets]
set fd [open "data.txt"]
fconfigure $fd -encoding utf-8 -strictencoding 1
# That next line will hang indefinitely
set data [gets $fd]
puts "not reached"
close $fd
puts $data

I'm not sure how this is supposed to work 
but it surely should not work this way.
Referenced by6
  • 5966973d58Merge trunk c8983a2a94: Fix [154ed7ce56]: Tcl 9: [gets] on -strictencoding 1 configured channel. check-in2023-03-24 13:16:26
  • c02747a663Fix [154ed7ce56]: Tcl 9: [gets] on -strictencoding 1 configured channel check-in2023-03-21 08:44:37
  • a338fcd542Proposed fix for [154ed7ce56]: Tcl 9: [gets] on -strictencoding 1 configured channel. Extracted from TIP #657 branch (better keeping bug-fix separate from enhancements) check-in2023-03-20 22:53:33
  • 4cdf4836aaFix for [b8f575aa2398b0e4], and also for [154ed7ce56], Tcl 9: [gets] on -strictencoding 1 configured channel. check-in2023-01-17 20:09:49
  • 8c5d9bcc6eMerge py-b8f575aa23: Fix for [154ed7ce56], Tcl 9: [gets] on -strictencoding 1 configured channel. check-in2023-01-02 23:12:02
  • 003c9e1f2eFix for [154ed7ce56], Tcl 9: [gets] on -strictencoding 1 configured channel. check-in2023-01-02 21:07:02
pointsman Ticket [154ed7ce56]: 3 changes [History diff]2022-12-22 13:27:51
jan.nijtmanswiki2022-12-22 14:45:58

Expected behavior: same as "read".

pointsmanplain2022-12-25 00:14:28
You mean: Instead of the hang gets will return the line read so
far in this situation (without raising error) and will raise
error only on the next gets on the same channel?

Please not. Please consider rasing error in the first place
(and change "read" in the same way).
pooryorickwiki2023-01-02 21:10:21

Fixed in [003c9e1f2e53312b]: [gets] returns an error when a decoding error occurs, and data successfully decoded up until the error is available in the "-result" entry of the return options.

pooryorickwiki2023-01-17 22:09:05

See issue [b8f575aa2398b0e4], where this issue is discussed for both [read] and [gets], and multiple alternative fixes are provided.

pooryorickwiki2023-02-18 01:16:24

The commit that caused this broken behaviour of [gets] was [a106c26dd5e8934f], "TIP #346: Error on Failed String Encodings".

jan.nijtmansmarkdown2023-02-23 15:22:41

From Ashok's document:

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,

% 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

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.

jan.nijtmanswiki2023-03-21 09:17:23

Fixed [here], as discussed. In blocking mode, the exception is thrown immediately. In non-blocking mode, data read so far is returned.

If an exception is thrown, there is no way to get back the read data so far, that will be handled in a separate TIP.

Log in (anonymous is fine) to add a comment.