pico
created pr with
ps-210
changed status to
accepted
cmds
checkout latest patchset:
ssh pr.pico.sh print pr-118 | git am -3checkout any patchset in a patch request:
ssh pr.pico.sh print ps-X | git am -3add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 118set PR to open (enables RSS notifications):
ssh pr.pico.sh pr open 118set PR to draft (stops RSS notifications):
ssh pr.pico.sh pr draft 118
Patchset
ps-210
fix(pssh): normalize line ending with pty
Eric Bower
2026-02-26T03:13:25ZSemantic diff summary
1 added,
1 modified,
0 signature changed,
0 removed
across 1 analyzed file
+27
-0
pkg/pssh/server.go
#
@@ -1,6 +1,7 @@
package pssh
import (
+ "bytes"
"context"
"crypto/ed25519"
"crypto/rand"
@@ -185,6 +186,32 @@ func (s *SSHServerConnSession) Pty() (*Pty, <-chan Window, bool) {
return s.pty, s.winch, true
}
+// Write overrides the embedded Channel's Write to normalize line endings when PTY is allocated.
+func (s *SSHServerConnSession) Write(p []byte) (n int, err error) {
+ s.mu.Lock()
+ hasPty := s.pty != nil
+ s.mu.Unlock()
+
+ if !hasPty {
+ // No PTY, write as-is
+ return s.Channel.Write(p)
+ }
+
+ // When PTY is active, normalize line endings like a real terminal would.
+ // Replace \n with \r\n, but avoid double \r\n.
+ normalized := bytes.ReplaceAll(p, []byte{'\n'}, []byte{'\r', '\n'})
+ normalized = bytes.ReplaceAll(normalized, []byte{'\r', '\r', '\n'}, []byte{'\r', '\n'})
+
+ // Write the normalized data
+ written, err := s.Channel.Write(normalized)
+
+ // Return the count based on original data length, not normalized
+ if written > len(p) {
+ written = len(p)
+ }
+ return written, err
+}
+
var _ context.Context = &SSHServerConnSession{}
func (sc *SSHServerConn) Handle(chans <-chan ssh.NewChannel, reqs <-chan *ssh.Request) error {