diff --git a/keymap/vi_test.sh b/keymap/vi_test.sh index 91138f13..f12f1221 100644 --- a/keymap/vi_test.sh +++ b/keymap/vi_test.sh @@ -39,10 +39,13 @@ function ble/keymap:vi_test/check { ((ntest++,nsuccess++)) else ((ntest++)) + local esc_in=${in//$nl/"$NL"} + local esc_fin=${fin//$nl/"$NL"} + local esc_str=${_ble_edit_str//$nl/"$NL"} ble/util/print "test($section/$id): keys = ($kspecs)" - ble/util/print " initial = \"$i:${in//$nl/"$NL"}\"" - ble/util/print " expected = \"$f:${fin//$nl/"$NL"}\"" - ble/util/print " result = \"$_ble_edit_ind:${_ble_edit_str//$nl/"$NL"}\"" + ble/util/print " initial = \"$i:$esc_in\"" + ble/util/print " expected = \"$f:$esc_fin\"" + ble/util/print " result = \"$_ble_edit_ind:$esc_str\"" fi >&2 # restore states diff --git a/lib/core-syntax.sh b/lib/core-syntax.sh index e9966b4b..1fc1608b 100644 --- a/lib/core-syntax.sh +++ b/lib/core-syntax.sh @@ -3625,10 +3625,10 @@ function ble/syntax:bash/ctx-heredoc-word/remove-quotes { if rex='^\$?"(([^\"]|\\.)*)(\\?$|")'; [[ $text =~ $rex ]]; then local str=${BASH_REMATCH[1]} local a b - b='\`' a='`'; str="${str//"$b"/"$a"}" - b='\"' a='"'; str="${str//"$b"/"$a"}" - b='\$' a='$'; str="${str//"$b"/"$a"}" - b='\\' a='\'; str="${str//"$b"/"$a"}" + b='\`' a='`'; str=${str//"$b"/"$a"} + b='\"' a='"'; str=${str//"$b"/"$a"} # WA #D1751 safe + b='\$' a='$'; str=${str//"$b"/"$a"} + b='\\' a='\'; str=${str//"$b"/"$a"} result=$result$str text=${text:${#BASH_REMATCH}} continue @@ -3664,12 +3664,12 @@ function ble/syntax:bash/ctx-heredoc-word/escape-delimiter { local ret=$1 if [[ $ret == *[\\\'$_ble_syntax_bash_IFS$_ble_term_FS]* ]]; then local a b fs=$_ble_term_FS - a=\\ ; b="\\$a"; ret="${ret//"$a"/"$b"}" - a=\' ; b="\\$a"; ret="${ret//"$a"/"$b"}" - a=' ' ; b="$_ble_syntax_bash_heredoc_EscSP"; ret="${ret//"$a"/"$b"}" - a=$'\t'; b="$_ble_syntax_bash_heredoc_EscHT"; ret="${ret//"$a"/"$b"}" - a=$'\n'; b="$_ble_syntax_bash_heredoc_EscLF"; ret="${ret//"$a"/"$b"}" - a=$fs ; b="$_ble_syntax_bash_heredoc_EscFS"; ret="${ret//"$a"/"$b"}" + a=\\ ; b='\'$a; ret=${ret//"$a"/"$b"} + a=\' ; b='\'$a; ret=${ret//"$a"/"$b"} + a=' ' ; b=$_ble_syntax_bash_heredoc_EscSP; ret=${ret//"$a"/"$b"} + a=$'\t'; b=$_ble_syntax_bash_heredoc_EscHT; ret=${ret//"$a"/"$b"} + a=$'\n'; b=$_ble_syntax_bash_heredoc_EscLF; ret=${ret//"$a"/"$b"} + a=$fs ; b=$_ble_syntax_bash_heredoc_EscFS; ret=${ret//"$a"/"$b"} fi escaped=$ret } diff --git a/make_command.sh b/make_command.sh index 196ad4f3..c7c404de 100755 --- a/make_command.sh +++ b/make_command.sh @@ -169,6 +169,11 @@ function sub:check/bash502-patsub_replacement { \Z#D1738Zd \Z\$\{_ble_edit_str//\$'\''\\n'\''/\$'\''\\n'\''"\$comment_begin"\}Zd # edit.sh g' + + grc --color '"[^"]*\$\{[[:alnum:]_]+(\[[^][]*\])?//?([^{}]|\{[^{}]*\})+/[^{}"'\'']*"[^"]*([&$]|\\)' --exclude=./test | + sed -E 'h;s/'"$esc"'//g;s/^[^:]*:[0-9]+:[[:space:]]*// + \Z#D1751Zd + g' } function sub:check/gawk402bug-regex-check { diff --git a/src/decode.sh b/src/decode.sh index 2184942b..0747a6ef 100644 --- a/src/decode.sh +++ b/src/decode.sh @@ -2119,7 +2119,7 @@ function ble-decode-bind/.generate-source-to-unbind-default/.process { local q=\' b=\\ Q="'\''" # Note: Solaris xpg4 awk では gsub の置換後のエスケープシーケンスも処理される [[ $_ble_bin_awk_solaris_xpg4 == yes ]] && Q="'$b$b''" - local QUOT_Q=\"${Q//"$b"/"$b$b"}\" + local QUOT_Q=\"${Q//"$b"/"$b$b"}\" # WA #D1751 checked LC_ALL=C ble/bin/awk -v q="$q" ' BEGIN { Q = '"$QUOT_Q"'; diff --git a/src/edit.sh b/src/edit.sh index f7ca08f4..e813b5c1 100644 --- a/src/edit.sh +++ b/src/edit.sh @@ -263,14 +263,9 @@ function ble-edit/prompt/.load { ## @var[out] DRAW_BUFF[] ## 出力先の配列です。 function ble-edit/prompt/print { - local text=$1 a b - if [[ $text == *['$\"`']* ]]; then - a='\' b='\\' text=${text//"$a"/"$b"} - a='$' b='\$' text=${text//"$a"/"$b"} - a='"' b='\"' text=${text//"$a"/"$b"} - a='`' b='\`' text=${text//"$a"/"$b"} - fi - ble/canvas/put.draw "$text" + local ret=$1 + ble/string#escape-characters "$ret" '\$"`' + ble/canvas/put.draw "$ret" } ## 関数 ble-edit/prompt/process-prompt-string prompt_string diff --git a/src/util.sh b/src/util.sh index 850e958e..dcc0b48e 100644 --- a/src/util.sh +++ b/src/util.sh @@ -4,7 +4,7 @@ #------------------------------------------------------------------------------ # ble.sh options -## 関数 bleopt args... +## @fn bleopt args... ## @params[in] args ## args は以下の内の何れかの形式を持つ。 ## @@ -402,8 +402,10 @@ function ble/array#last-index { function ble/dense-array#fill-range { ble/array#reserve-prototype $(($3-$2)) local _ble_script=' - local -a sARR; sARR=("${_ble_array_prototype[@]::$3-$2}") - ARR=("${ARR[@]::$2}" "${sARR[@]/#/"$4"}" "${ARR[@]:$3}")' # WA #D1570 checked + local -a sARR; sARR=("${_ble_array_prototype[@]::$3-$2}") + ARR=("${ARR[@]::$2}" "${sARR[@]/#/$4}" "${ARR[@]:$3}")' # WA #D1570 #D1738 checked + ((_ble_bash>=40300)) && ! shopt -q compat42 && + _ble_script=${_ble_script//'$4'/'"$4"'} builtin eval -- "${_ble_script//ARR/$1}" } @@ -422,7 +424,7 @@ function ble/string#reserve-prototype { function ble/string#repeat { ble/string#reserve-prototype "$2" ret=${_ble_string_prototype::$2} - ret="${ret// /"$1"}" + ret=${ret// /"$1"} } ## 関数 ble/string#common-prefix a b @@ -731,7 +733,7 @@ function ble/string#escape-for-bash-single-quote { function ble/string#escape-for-bash-double-quote { ble/string#escape-characters "$1" '\"$`' local a b - a='!' b='"\!"' ret=${ret//"$a"/"$b"} + a='!' b='"\!"' ret=${ret//"$a"/"$b"} # WA #D1751 checked } function ble/string#escape-for-bash-escape-string { ble/string#escape-characters "$1" $'\\\a\b\e\f\n\r\t\v'\' '\abefnrtv'\' @@ -758,7 +760,7 @@ function ble/string#escape-for-bash-specialchars { if [[ $ret == *[$']\n\t']* ]]; then local a b a=']' b=\\$a ret=${ret//"$a"/"$b"} - a=$'\n' b="\$'\n'" ret=${ret//"$a"/"$b"} + a=$'\n' b="\$'\n'" ret=${ret//"$a"/"$b"} # WA #D1751 checked a=$'\t' b=$'\\\t' ret=${ret//"$a"/"$b"} fi @@ -832,7 +834,7 @@ function ble/string#escape-for-bash-specialchars-in-brace { if [[ $ret == *[$']\n\t']* ]]; then local a b a=']' b=\\$a ret=${ret//"$a"/"$b"} - a=$'\n' b="\$'\n'" ret=${ret//"$a"/"$b"} + a=$'\n' b="\$'\n'" ret=${ret//"$a"/"$b"} # WA #D1751 checked a=$'\t' b=$' \t' ret=${ret//"$a"/"$b"} fi } @@ -923,7 +925,8 @@ function ble/util/substr { function ble/path#add { local _ble_local_script='opts=$opts${opts:+:}$2' - builtin eval -- "${_ble_local_script//opts/"$1"}" + _ble_local_script=${_ble_local_script//opts/"$1"} + builtin eval -- "$_ble_local_script" } function ble/path#remove { [[ $2 ]] || return @@ -931,7 +934,8 @@ function ble/path#remove { opts=:${opts//:/::}: opts=${opts//:"$2":} opts=${opts//::/:} opts=${opts#:} opts=${opts%:}' - builtin eval -- "${_ble_local_script//opts/"$1"}" + _ble_local_script=${_ble_local_script//opts/"$1"} + builtin eval -- "$_ble_local_script" } function ble/path#remove-glob { [[ $2 ]] || return @@ -939,7 +943,8 @@ function ble/path#remove-glob { opts=:${opts//:/::}: opts=${opts//:$2:} opts=${opts//::/:} opts=${opts#:} opts=${opts%:}' - builtin eval -- "${_ble_local_script//opts/"$1"}" + _ble_local_script=${_ble_local_script//opts/"$1"} + builtin eval -- "$_ble_local_script" } if ((_ble_bash>=40000)); then @@ -3275,7 +3280,8 @@ function ble/term/cursor-state/.update { local state=$(($1)) [[ $_ble_term_cursor_current == "$state" ]] && return - ble/util/buffer "${_ble_term_Ss//@1/"$state"}" + local esc=${_ble_term_Ss//@1/"$state"} + ble/util/buffer "$esc" _ble_term_cursor_current=$state }