Closed yjyao closed 11 months ago
This is excellent! Thanks for the fix, and the thorough explanation. Much appreciated! I added a small integration test to verify this behavior with running copies of tmux, and that appears to be green for all versions of tmux we're testing against.
Released in 0.14.1. Thanks!
Many regexes contain escaped characters like
\s
or\w
.tmux-fastcopy
queries the tmux environment for regex overwrites. Specifically, it uses thetmux show-options -g
command. The output in turn escapes the backward slashes, turning\s
into\\s
. To correctly parse the regex overwrites,tmux-fastcopy
needs to unescape these backward slashes too.The
tmux show-options -g
command prints values in three forms:Unquoted for simple, unspaced values:
Single-quoted for simple, double-quoted values:
Double-quoted for other values:
Note that the output escapes backward slashes in all three forms:
For many regexes, tmux would print the value unquoted. For example, the path regex built-in to
tmux-fastcopy
is like this:Currently,
tmux-fastcopy
relies onstrconv.Unquote
in thetmuxopt.Loader.ReadValue
function to unescape the backslashes. However, a caveat is thatstrconv.Unquote
only performs if the given string is quoted. As a result,tmux-fastcopy
never unescapes the regex from the last paragraph, and would fail to match it.This commit fixes the problem by manually double-quoting unquoted strings, forcing
strconv.Unquote
to unescape them.(The above results were tested with tmux 3.3a in bash 5.2.15(1)-release.)
TIP: Before this PR is merged (if ever), a workaround is to force tmux to double-quote the value for example by prefixing your regex with a
"{0}
which matches nothing.