Skip to content

Commit 43098e5

Browse files
committed
test(zsh): add regression test for bracketed-paste GLOB_SUBST fix
Extracts the shipped zle_bracketed_paste statements from the embedded init script and drives them under setopt glob_subst, so drift between the code we ship and what's tested is caught. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SAb3Bs4xBBQhweDvCh59b7
1 parent f9d2313 commit 43098e5

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

src/shell/zsh_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,40 @@ func zshIsBufferComplete(t *testing.T) string {
4242
return signature + body + "\n}\n"
4343
}
4444

45+
// Under setopt GLOB_SUBST, an unquoted parameter expansion is eligible for
46+
// filename generation as if it had been typed literally. The bracketed-paste
47+
// escape sequence (\e[?2004h) then parses as an unterminated bracket
48+
// expression, which zsh's default BAD_PATTERN option turns into a hard
49+
// error - see https://github.com/JanDeDobbeleer/oh-my-posh/issues/7816.
50+
func TestZshBracketedPasteGlobSubst(t *testing.T) {
51+
if _, err := exec.LookPath("zsh"); err != nil {
52+
t.Skip("zsh is not installed")
53+
}
54+
55+
const signature = "function _omp_zle-line-init() {"
56+
_, body, found := strings.Cut(zshInit, signature)
57+
require.True(t, found, "_omp_zle-line-init is missing from omp.zsh")
58+
59+
var lines []string
60+
for _, line := range strings.Split(body, "\n") {
61+
if strings.Contains(line, "zle_bracketed_paste") {
62+
lines = append(lines, strings.TrimSpace(line))
63+
}
64+
}
65+
require.Len(t, lines, 2, "expected exactly two zle_bracketed_paste statements in _omp_zle-line-init")
66+
67+
script := "setopt glob_subst\n" +
68+
`zle_bracketed_paste=($'\e[?2004h' $'\e[?2004l')` + "\n" +
69+
strings.Join(lines, "\n")
70+
71+
home := t.TempDir()
72+
cmd := exec.CommandContext(t.Context(), "zsh", "-f", "-c", script)
73+
cmd.Env = []string{"HOME=" + home, "PATH=" + os.Getenv("PATH")}
74+
75+
out, err := cmd.CombinedOutput()
76+
assert.NoError(t, err, string(out))
77+
}
78+
4579
// Zsh reports an unterminated here-document as syntactically fine, so the
4680
// here-document cases below are the interesting ones.
4781
func TestZshIsBufferComplete(t *testing.T) {

0 commit comments

Comments
 (0)