Skip to content

Commit fdca2ef

Browse files
committed
main: Fix off by one errors in quote helper functions
1 parent e130745 commit fdca2ef

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

highlighters/main/main-highlighter.zsh

+10-2
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,8 @@ _zsh_highlight_main_highlighter_highlight_single_quote()
888888
if [[ $arg[i] == "'" ]]; then
889889
style=single-quoted-argument
890890
else
891+
# If unclosed, i points past the end
892+
(( i-- ))
891893
style=single-quoted-argument-unclosed
892894
fi
893895
reply=($(( start_pos + arg1 - 1 )) $(( start_pos + i )) $style $reply)
@@ -902,7 +904,7 @@ _zsh_highlight_main_highlighter_highlight_double_quote()
902904
local i j k style
903905
reply=()
904906

905-
for (( i = $1 + 1 ; i < end_pos - start_pos ; i += 1 )) ; do
907+
for (( i = $1 + 1 ; i <= end_pos - start_pos ; i += 1 )) ; do
906908
(( j = i + start_pos - 1 ))
907909
(( k = j + 1 ))
908910
case "$arg[$i]" in
@@ -959,6 +961,8 @@ _zsh_highlight_main_highlighter_highlight_double_quote()
959961
if [[ $arg[i] == '"' ]]; then
960962
style=double-quoted-argument
961963
else
964+
# If unclosed, i points past the end
965+
(( i-- ))
962966
style=double-quoted-argument-unclosed
963967
fi
964968
reply=($(( start_pos + $1 - 1)) $(( start_pos + i )) $style $reply)
@@ -975,7 +979,7 @@ _zsh_highlight_main_highlighter_highlight_dollar_quote()
975979
integer c
976980
reply=()
977981

978-
for (( i = $1 + 2 ; i < end_pos - start_pos ; i += 1 )) ; do
982+
for (( i = $1 + 2 ; i <= end_pos - start_pos ; i += 1 )) ; do
979983
(( j = i + start_pos - 1 ))
980984
(( k = j + 1 ))
981985
case "$arg[$i]" in
@@ -1011,6 +1015,8 @@ _zsh_highlight_main_highlighter_highlight_dollar_quote()
10111015
if [[ $arg[i] == "'" ]]; then
10121016
style=dollar-quoted-argument
10131017
else
1018+
# If unclosed, i points past the end
1019+
(( i-- ))
10141020
style=dollar-quoted-argument-unclosed
10151021
fi
10161022
reply=($(( start_pos + $1 - 1 )) $(( start_pos + i )) $style $reply)
@@ -1027,6 +1033,8 @@ _zsh_highlight_main_highlighter_highlight_backtick()
10271033
if [[ $arg[i] == '`' ]]; then
10281034
style=back-quoted-argument
10291035
else
1036+
# If unclosed, i points past the end
1037+
(( i-- ))
10301038
style=back-quoted-argument-unclosed
10311039
fi
10321040
reply=($(( start_pos + arg1 - 1 )) $(( start_pos + i )) $style)

0 commit comments

Comments
 (0)