Skip to content

Commit a907781

Browse files
authored
fix: use UTF-8 encoding with screen (#10190)
This will make characters like ❯ and ⇣ work, for example.
1 parent a67a5a8 commit a907781

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

agent/agent_test.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,11 +1544,13 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
15441544
_, err := exec.LookPath("screen")
15451545
hasScreen := err == nil
15461546

1547+
// Make sure UTF-8 works even with LANG set to something like C.
1548+
t.Setenv("LANG", "C")
1549+
15471550
for _, backendType := range backends {
15481551
backendType := backendType
15491552
t.Run(backendType, func(t *testing.T) {
15501553
if backendType == "Screen" {
1551-
t.Parallel()
15521554
if runtime.GOOS != "linux" {
15531555
t.Skipf("`screen` is not supported on %s", runtime.GOOS)
15541556
} else if !hasScreen {
@@ -1563,8 +1565,6 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
15631565
err = os.Symlink(bashPath, filepath.Join(dir, "bash"))
15641566
require.NoError(t, err, "symlink bash into reconnecting pty PATH")
15651567
t.Setenv("PATH", dir)
1566-
} else {
1567-
t.Parallel()
15681568
}
15691569

15701570
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
@@ -1656,6 +1656,17 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
16561656
tr4 := testutil.NewTerminalReader(t, netConn4)
16571657
require.NoError(t, tr4.ReadUntil(ctx, matchEchoOutput), "find echo output")
16581658
require.ErrorIs(t, tr4.ReadUntil(ctx, nil), io.EOF)
1659+
1660+
// Ensure that UTF-8 is supported. Avoid the terminal emulator because it
1661+
// does not appear to support UTF-8, just make sure the bytes that come
1662+
// back have the character in it.
1663+
netConn5, err := conn.ReconnectingPTY(ctx, uuid.New(), 80, 80, "echo ❯")
1664+
require.NoError(t, err)
1665+
defer netConn5.Close()
1666+
1667+
bytes, err := io.ReadAll(netConn5)
1668+
require.NoError(t, err)
1669+
require.Contains(t, string(bytes), "❯")
16591670
})
16601671
}
16611672
}

agent/reconnectingpty/screen.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,13 @@ func (rpty *screenReconnectingPTY) doAttach(ctx context.Context, conn net.Conn,
206206
cmd := pty.CommandContext(ctx, "screen", append([]string{
207207
// -S is for setting the session's name.
208208
"-S", rpty.id,
209+
// -U tells screen to use UTF-8 encoding.
209210
// -x allows attaching to an already attached session.
210211
// -RR reattaches to the daemon or creates the session daemon if missing.
211212
// -q disables the "New screen..." message that appears for five seconds
212213
// when creating a new session with -RR.
213214
// -c is the flag for the config file.
214-
"-xRRqc", rpty.configFile,
215+
"-UxRRqc", rpty.configFile,
215216
rpty.command.Path,
216217
// pty.Cmd duplicates Path as the first argument so remove it.
217218
}, rpty.command.Args[1:]...)...)

0 commit comments

Comments
 (0)