diff options
| author | Frank LENORMAND <lenormf@gmail.com> | 2015-12-02 13:05:48 +0300 |
|---|---|---|
| committer | Frank LENORMAND <lenormf@gmail.com> | 2015-12-02 15:22:31 +0300 |
| commit | c40dba8a208ccf68ac4e7cb43654b069966117ae (patch) | |
| tree | c63f9407030dd8fe104cc8549a115b3d88587937 | |
| parent | c84f06300ab2e878babd196723440b6ae1bc7e08 (diff) | |
Escape additional characters that could be interpreted by the regex/exec engine
| -rw-r--r-- | rc/commenting.kak | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/rc/commenting.kak b/rc/commenting.kak index 7fa7caed..076e4027 100644 --- a/rc/commenting.kak +++ b/rc/commenting.kak @@ -8,11 +8,15 @@ def comment-selection -docstring "Comment/uncomment the current selection" %{ %sh{ function escape_regex_chars { ## Escape characters that can be interpreted as modifiers/repetitors by the regex engine - sed -r 's,(\*|\+|\[|\]|\{\}|\||\(|\)|\?),\\\1,g' <<< "$@" + sed -r 's,(\*|\+|\[|\]|\{\}|\||\(|\)|\?|\^|\$),\\\1,g' <<< "$@" + } + function exec_proof { + ## Replace some special characters that are interpreted differently in `exec` + sed -r -e 's,<,<lt,g' -e 's,>,gt>,g' -e 's,<lt\b,<lt>,g' -e 's,\bgt>,<gt>,g' <<< "$@" } - readonly opening="${kak_opt_comment_selection_chars%%:*}" - readonly closing="${kak_opt_comment_selection_chars##*:}" + readonly opening=$(exec_proof "${kak_opt_comment_selection_chars%%:*}") + readonly closing=$(exec_proof "${kak_opt_comment_selection_chars##*:}") readonly opening_escaped=$(escape_regex_chars "${opening}") readonly closing_escaped=$(escape_regex_chars "${closing}") |
