Skip to content
Myr

Escape trailing semicolon in tmux command argument

Before adoption: this commit came in with the history the project adopted, so no landing records it.

tmux ends a command at an argument whose last character is ';', so a --border-label ending in one was stored truncated. escapeTmuxSeparator only covered a value that was exactly ';'. fzf --popup --border-label 'foo;' -> @fzf-border-label was 'foo'

authored by Junegunn Choi · committed by Junegunn Choi · parent 50e6c02 · Browse files · 2 files+11 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+11 added−5 removed

  • other:+11 added−5 removed

2 files+11 added−5 removed

modified:src/tmux_test.go+7 added-1 removed
16 unmodified lines
17 {"#{pane_id}", "##{pane_id}"},18 {" C# notes #S ", " C## notes ##S "},19 {";", `\;`},20 {"; rm", "; rm"},21 {"C#;", `C##\;`},22 } {23 if actual := escapeTmuxFormat(tc.given); actual != tc.expected {24 t.Errorf("expected %q, got %q", tc.expected, actual)25 }
9 unmodified lines
35 {" fzf ", " fzf "},36 {"#", "#"},37 {"#{pane_id}", "#{pane_id}"},38 {"100%", "100%"},39 // tmux drops a trailing ';' and everything after it, so only that40 // one is escaped41 {";", `\;`},42 {"abc;", `abc\;`},43 {";;", `;\;`},44 {`foo\;`, `foo\\;`},45 {"; rm", "; rm"},46 {" ; ", " ; "},41 {";;", ";;"},47 {"a;b", "a;b"},48 } {49 if actual := escapeTmuxSeparator(tc.given); actual != tc.expected {50 t.Errorf("expected %q, got %q", tc.expected, actual)51 }
2 unmodified lines
modified:src/tmux.go+4 added-4 removed
44 unmodified lines
45 }46 return width, height, true47}4849// A lone ';' argument is a command separator to tmux, aborting the whole50// command at parse time49// tmux ends a command at an argument ending in ';', so a trailing one is50// escaped. Elsewhere it is not special51func escapeTmuxSeparator(str string) string {52 if str == ";" {53 return `\;`52 if strings.HasSuffix(str, ";") {53 return str[:len(str)-1] + `\;`54 }55 return str56}57
211 unmodified lines