Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Unescaping certain regex options.
Many regexes contain escaped characters like `\s` or `\w`. `tmux-fastcopy` queries the tmux environment for regex overwrites. Specifically, it uses the `tmux 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: ```shell $ tmux set @myopt hey ; tmux show @myopt @myopt hey ``` - Single-quoted for simple, double-quoted values: ```shell $ tmux set @myopt hey\"world ; tmux show @myopt @myopt 'hey"world' ``` - Double-quoted for other values: ```shell $ tmux set @myopt hey\ ; tmux show @myopt @myopt "hey " ``` Note that the output escapes backward slashes in all three forms: ```shell $ tmux set @myopt '\hey' ; tmux show @myopt @myopt \\hey $ tmux set @myopt '\"hey' ; tmux show @myopt @myopt '\\"hey' $ tmux set @myopt '\ hey' ; tmux show @myopt @myopt "\\ hey" ``` For many regexes, tmux would print the value unquoted. For example, the path regex built-in to `tmux-fastcopy` is like this: ```shell $ tmux set-option @myopt '(\b([\w.-]+|~)?(/[\w.-]+)+\b)' ; tmux show @myopt @myopt (\\b([\\w.-]+|~)?(/[\\w.-]+)+\\b) ``` Currently, `tmux-fastcopy` relies on `strconv.Unquote` in the `tmuxopt.Loader.ReadValue` function to unescape the backslashes. However, a caveat is that `strconv.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.
- Loading branch information