Tcl Source Code

View Ticket
Login
Ticket UUID: 4c5a98f5a0d4ae30a0f1bb4d76592f3ba3551bd1
Title: gets with -translation auto merges lines after a "\r" at the end of a read
Type: Bug Created on: 2026-10-16 21:38:18
Submitter: serhiy.storchaka Assigned to:
Subsystem: 25. Channel System Severity: Minor
Priority: 5 Medium Last modified: 2026-10-16 21:40:49
Status: Open Closed by:
Resolution: None Closed on:
Version: 8.6.18, 9.0.5, 9.1.0
Description:

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.

User Comments:
serhiy.storchaka added on 2026-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.