gets with -translation auto merges lines after a "\r" at the end of a read
Closed / Fixed4c5a98f5a0d4ae30a0f1bb4d76592f3ba3551bd1Created 47 days agoUpdated 10 days ago
Descriptionwiki2026-10-16 21:38:18
With -translation auto, if a read ends with "\r" and the next read has no end of line, a "\n" at the start of a later read is dropped as if it were the LF of a CRLF pair:
lassign [chan pipe] r w fconfigure $r -blocking 0 -translation auto fconfigure $w -translation binary -buffering none puts -nonewline $w "a\r"; gets $r ;# a puts -nonewline $w "b"; gets $r ;# (blocked) puts -nonewline $w "\nc\n"; gets $r ;# bc (8.6.12: b, then c)
LF CR input loses empty lines in the same way. Since [a3ed092aab] (8.6.13, the fix for [b3977d199b]) Tcl_GetsObj() resets INPUT_SAW_CR only when an end of line is found.
Referenced by3
7562e15fe4Closed ticket [2953593fff]: [gets $fd data] returns 0 in nonblocking mode plus 4 other changes ticket2026-10-16 21:44:20f5e82977a2Ticket [2953593fff] [gets $fd data] returns 0 in nonblocking mode status still Open with 3 other changes ticket2026-10-16 21:40:497d959464b9Fix [4c5a98f5a0]: gets with -translation auto merged lines after a "\r" at the end of a read. Reset INPUT_SAW_CR as soon as data follows the "\r", and set it again if the skipped "\n" is pushed back, so that the case of [b3977d199b] still works. check-in2026-10-16 21:40:08
serhiy.storchakawiki2026-10-16 21:40:49
Proposed fix in branch gets-auto-saw-cr: Tcl_GetsObj() resets INPUT_SAW_CR as soon as data follows the "\r" and sets it again if the skipped "\n" is pushed back, so the torn CRLF case of [b3977d199b] still works (io-29.36.1, io-29.36.2). Test io-29.36.3.
jan.nijtmanswiki2026-11-22 22:56:47
Merged to [trunk], core-9-0-branch and core-8-6-branch
Many thanks!
Log in (anonymous is fine) to add a comment.