pico
created pr with
118.1
changed status to
accepted
cmds
checkout latest patchset:
ssh pr.pico.sh print 118 | git am -3checkout any patchset in a patch request:
ssh pr.pico.sh print 118.[rev] | 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
118.1
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
#
| ... | ... | @@ -185,6 +186,32 @@ func (s *SSHServerConnSession) Pty() (*Pty, <-chan Window, bool) { | |
| 185 | 186 | return s.pty, s.winch, true | |
| 186 | 187 | } | |
| 187 | 188 | ||
| 189 | + | // Write overrides the embedded Channel's Write to normalize line endings when PTY is allocated. | |
| 190 | + | func (s *SSHServerConnSession) Write(p []byte) (n int, err error) { | |
| 191 | + | s.mu.Lock() | |
| 192 | + | hasPty := s.pty != nil | |
| 193 | + | s.mu.Unlock() | |
| 194 | + | ||
| 195 | + | if !hasPty { | |
| 196 | + | // No PTY, write as-is | |
| 197 | + | return s.Channel.Write(p) | |
| 198 | + | } | |
| 199 | + | ||
| 200 | + | // When PTY is active, normalize line endings like a real terminal would. | |
| 201 | + | // Replace \n with \r\n, but avoid double \r\n. | |
| 202 | + | normalized := bytes.ReplaceAll(p, []byte{'\n'}, []byte{'\r', '\n'}) | |
| 203 | + | normalized = bytes.ReplaceAll(normalized, []byte{'\r', '\r', '\n'}, []byte{'\r', '\n'}) | |
| 204 | + | ||
| 205 | + | // Write the normalized data | |
| 206 | + | written, err := s.Channel.Write(normalized) | |
| 207 | + | ||
| 208 | + | // Return the count based on original data length, not normalized | |
| 209 | + | if written > len(p) { | |
| 210 | + | written = len(p) | |
| 211 | + | } | |
| 212 | + | return written, err | |
| 213 | + | } | |
| 214 | + | ||
| 188 | 215 | var _ context.Context = &SSHServerConnSession{} | |
| 189 | 216 | ||
| 190 | 217 | func (sc *SSHServerConn) Handle(chans <-chan ssh.NewChannel, reqs <-chan *ssh.Request) error { |