From c40dba8a208ccf68ac4e7cb43654b069966117ae Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Wed, 2 Dec 2015 13:05:48 +0300 Subject: [PATCH] Escape additional characters that could be interpreted by the regex/exec engine --- rc/commenting.kak | 10 +++++++--- 1 file 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,<,,gt>,g' -e 's,,g' -e 's,\bgt>,,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}")