From 64882848149385856435d18497c2f5aa82741fc4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 25 Sep 2015 21:36:20 +0000 Subject: [PATCH] back-dollar-quoted-argument: Highlight incomplete escape sequences as unknown-token Followup to 219184f046d40cc723606797666dab18f8a6aea7, which fixed issue #196. --- highlighters/main/main-highlighter.zsh | 4 ++++ highlighters/main/test-data/dollar-quoted2.zsh | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 27f35a3..b53dcee 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -332,6 +332,10 @@ _zsh_highlight_main_highlighter_highlight_dollar_string() (( k += $#MATCH )) (( i += $#MATCH )) else + if (( $#arg > $i+1 )) && [[ $arg[$i+1] == [xXuU] ]]; then + # \x not followed by hex digits is probably an error + style=$ZSH_HIGHLIGHT_STYLES[unknown-token] + fi (( k += 1 )) # Color following char too. (( i += 1 )) # Skip parsing the escaped char. fi diff --git a/highlighters/main/test-data/dollar-quoted2.zsh b/highlighters/main/test-data/dollar-quoted2.zsh index ecaaa39..0eb482d 100644 --- a/highlighters/main/test-data/dollar-quoted2.zsh +++ b/highlighters/main/test-data/dollar-quoted2.zsh @@ -29,12 +29,14 @@ # ------------------------------------------------------------------------------------------------- ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]=$unused_highlight -BUFFER=": \$'foo\xbar\udeadbeef'" +BUFFER=": \$'foo\xbar\udeadbeef\uzzzz'" expected_region_highlight=( "3 7 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # $'foo "8 11 $ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]" # \xba "12 12 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # r "13 18 $ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]" # \dead - "19 23 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # beef' + "19 22 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # beef + "23 24 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # \u + "25 29 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # zzzz' )