main: Avoid $end_pos when calculating $arg size
Fixes second issue filed under #617 https://github.com/zsh-users/zsh-syntax-highlighting/issues/617#issuecomment-551253422 In the case of a command substitution in an alias, $arg[i,end_pos] would not pass to the end of $arg and i <= start_pos - end_pos would not iterate over all of $arg. Use $arg[i,-1] and $#arg respectively to avoid issues in aliases.
This commit is contained in:
		
							parent
							
								
									be3882aeb0
								
							
						
					
					
						commit
						139ea2b189
					
				|  | @ -807,7 +807,7 @@ _zsh_highlight_main_highlighter_highlight_list() | ||||||
|                             # Discard  :start_of_pipeline:, if present, as '!' is not valid |                             # Discard  :start_of_pipeline:, if present, as '!' is not valid | ||||||
|                             # after assignments. |                             # after assignments. | ||||||
|                             next_word+=':start:' |                             next_word+=':start:' | ||||||
|                             if (( start_pos + i <= end_pos )); then |                             if (( i <= $#arg )); then | ||||||
|                               () { |                               () { | ||||||
|                                 local highlight_glob=false |                                 local highlight_glob=false | ||||||
|                                 [[ $zsyh_user_options[globassign] == on ]] && highlight_glob=true |                                 [[ $zsyh_user_options[globassign] == on ]] && highlight_glob=true | ||||||
|  | @ -1030,7 +1030,7 @@ _zsh_highlight_main_highlighter_highlight_argument() | ||||||
|     '=') |     '=') | ||||||
|       if [[ $arg[i+1] == $'\x28' ]]; then |       if [[ $arg[i+1] == $'\x28' ]]; then | ||||||
|         (( i += 2 )) |         (( i += 2 )) | ||||||
|         _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,end_pos] |         _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,-1] | ||||||
|         ret=$? |         ret=$? | ||||||
|         (( i += REPLY )) |         (( i += REPLY )) | ||||||
|         highlights+=( |         highlights+=( | ||||||
|  | @ -1044,7 +1044,7 @@ _zsh_highlight_main_highlighter_highlight_argument() | ||||||
|       fi |       fi | ||||||
|   esac |   esac | ||||||
| 
 | 
 | ||||||
|   for (( ; i <= end_pos - start_pos ; i += 1 )); do |   for (( ; i <= $#arg ; i += 1 )); do | ||||||
|     case "$arg[$i]" in |     case "$arg[$i]" in | ||||||
|       "\\") (( i += 1 )); continue;; |       "\\") (( i += 1 )); continue;; | ||||||
|       "'") |       "'") | ||||||
|  | @ -1074,7 +1074,7 @@ _zsh_highlight_main_highlighter_highlight_argument() | ||||||
|        elif [[ $arg[i+1] == $'\x28' ]]; then |        elif [[ $arg[i+1] == $'\x28' ]]; then | ||||||
|           start=$i |           start=$i | ||||||
|           (( i += 2 )) |           (( i += 2 )) | ||||||
|           _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,end_pos] |           _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,-1] | ||||||
|           ret=$? |           ret=$? | ||||||
|           (( i += REPLY )) |           (( i += REPLY )) | ||||||
|           highlights+=( |           highlights+=( | ||||||
|  | @ -1097,7 +1097,7 @@ _zsh_highlight_main_highlighter_highlight_argument() | ||||||
|         if [[ $arg[i+1] == $'\x28' ]]; then # \x28 = open paren |         if [[ $arg[i+1] == $'\x28' ]]; then # \x28 = open paren | ||||||
|           start=$i |           start=$i | ||||||
|           (( i += 2 )) |           (( i += 2 )) | ||||||
|           _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,end_pos] |           _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,-1] | ||||||
|           ret=$? |           ret=$? | ||||||
|           (( i += REPLY )) |           (( i += REPLY )) | ||||||
|           highlights+=( |           highlights+=( | ||||||
|  | @ -1123,7 +1123,7 @@ _zsh_highlight_main_highlighter_highlight_argument() | ||||||
|     esac |     esac | ||||||
|   done |   done | ||||||
| 
 | 
 | ||||||
|   if (( path_eligible )) && _zsh_highlight_main_highlighter_check_path $arg[$1,end_pos]; then |   if (( path_eligible )) && _zsh_highlight_main_highlighter_check_path $arg[$1,-1]; then | ||||||
|     base_style=$REPLY |     base_style=$REPLY | ||||||
|     _zsh_highlight_main_highlighter_highlight_path_separators $base_style |     _zsh_highlight_main_highlighter_highlight_path_separators $base_style | ||||||
|     highlights+=($reply) |     highlights+=($reply) | ||||||
|  | @ -1175,7 +1175,7 @@ _zsh_highlight_main_highlighter_highlight_double_quote() | ||||||
|   local i j k ret style |   local i j k ret style | ||||||
|   reply=() |   reply=() | ||||||
| 
 | 
 | ||||||
|   for (( i = $1 + 1 ; i <= end_pos - start_pos ; i += 1 )) ; do |   for (( i = $1 + 1 ; i <= $#arg ; i += 1 )) ; do | ||||||
|     (( j = i + start_pos - 1 )) |     (( j = i + start_pos - 1 )) | ||||||
|     (( k = j + 1 )) |     (( k = j + 1 )) | ||||||
|     case "$arg[$i]" in |     case "$arg[$i]" in | ||||||
|  | @ -1206,7 +1206,7 @@ _zsh_highlight_main_highlighter_highlight_double_quote() | ||||||
|               breaks+=( $last_break $(( start_pos + i - 1 )) ) |               breaks+=( $last_break $(( start_pos + i - 1 )) ) | ||||||
|               (( i += 2 )) |               (( i += 2 )) | ||||||
|               saved_reply=($reply) |               saved_reply=($reply) | ||||||
|               _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,end_pos] |               _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,-1] | ||||||
|               ret=$? |               ret=$? | ||||||
|               (( i += REPLY )) |               (( i += REPLY )) | ||||||
|               last_break=$(( start_pos + i )) |               last_break=$(( start_pos + i )) | ||||||
|  | @ -1272,13 +1272,13 @@ _zsh_highlight_main_highlighter_highlight_dollar_quote() | ||||||
|   integer c |   integer c | ||||||
|   reply=() |   reply=() | ||||||
| 
 | 
 | ||||||
|   for (( i = $1 + 2 ; i <= end_pos - start_pos ; i += 1 )) ; do |   for (( i = $1 + 2 ; i <= $#arg ; i += 1 )) ; do | ||||||
|     (( j = i + start_pos - 1 )) |     (( j = i + start_pos - 1 )) | ||||||
|     (( k = j + 1 )) |     (( k = j + 1 )) | ||||||
|     case "$arg[$i]" in |     case "$arg[$i]" in | ||||||
|       "'") break;; |       "'") break;; | ||||||
|       "\\") style=back-dollar-quoted-argument |       "\\") style=back-dollar-quoted-argument | ||||||
|             for (( c = i + 1 ; c <= end_pos - start_pos ; c += 1 )); do |             for (( c = i + 1 ; c <= $#arg ; c += 1 )); do | ||||||
|               [[ "$arg[$c]" != ([0-9xXuUa-fA-F]) ]] && break |               [[ "$arg[$c]" != ([0-9xXuUa-fA-F]) ]] && break | ||||||
|             done |             done | ||||||
|             AA=$arg[$i+1,$c-1] |             AA=$arg[$i+1,$c-1] | ||||||
|  | @ -1333,7 +1333,7 @@ _zsh_highlight_main_highlighter_highlight_backtick() | ||||||
|   last=$(( arg1 + 1 )) |   last=$(( arg1 + 1 )) | ||||||
|   # Remove one layer of backslashes and find the end |   # Remove one layer of backslashes and find the end | ||||||
|   while i=$arg[(ib:i+1:)[\\\\\`]]; do # find the next \ or ` |   while i=$arg[(ib:i+1:)[\\\\\`]]; do # find the next \ or ` | ||||||
|     if (( i > end_pos - start_pos )); then |     if (( i > $#arg )); then | ||||||
|       buf=$buf$arg[last,i] |       buf=$buf$arg[last,i] | ||||||
|       offsets[i-arg1-offset]='' # So we never index past the end |       offsets[i-arg1-offset]='' # So we never index past the end | ||||||
|       (( i-- )) |       (( i-- )) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue