From 4590997ad975744e7d62cfd28d3ec80f248a9922 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sun, 16 Jan 2022 22:26:58 +0900 Subject: [PATCH] global: adjust implementations for bash-5.2 "patsub_replacement" --- .srcoption | 2 +- docs/ChangeLog.md | 1 + keymap/vi_test.sh | 10 +- lib/core-complete.sh | 2 +- lib/core-syntax.sh | 34 +-- make_command.sh | 25 +- memo/D1738.wa-old-patsub_replacement.patch | 298 +++++++++++++++++++++ note.txt | 63 +++++ src/canvas.sh | 4 +- src/decode.sh | 8 +- src/edit.sh | 14 +- src/history.sh | 20 +- src/util.sh | 102 ++++--- 13 files changed, 492 insertions(+), 91 deletions(-) create mode 100644 memo/D1738.wa-old-patsub_replacement.patch diff --git a/.srcoption b/.srcoption index 3b5d6510..6955e2d4 100644 --- a/.srcoption +++ b/.srcoption @@ -1,5 +1,5 @@ -x md:bash ---exclude=./{out,dist,tmp} +--exclude=./{out,dist,tmp,ext} --exclude=./?.sh --exclude=./test/install --exclude=./ble.sh diff --git a/docs/ChangeLog.md b/docs/ChangeLog.md index 7894ef2e..fec973eb 100644 --- a/docs/ChangeLog.md +++ b/docs/ChangeLog.md @@ -285,6 +285,7 @@ - main (`ble/util/readlink`): work around non-standard or missing `readlink` (motivated by peterzky) `#D1720` a41279e - menu (`menu-style:desc`): work around xenl quirks for relative cursor movements (reported by telometto) `#D1728` 3e136a6 - global: work around the arithmetic syntax error of `10#` in Bash-5.1 `#D1734` 0000000 +- global: adjust implementations for Bash 5.2 `patsub_replacement` `#D1738` 0000000 ## Internal changes and fixes diff --git a/keymap/vi_test.sh b/keymap/vi_test.sh index 88211cb5..bf94df57 100644 --- a/keymap/vi_test.sh +++ b/keymap/vi_test.sh @@ -40,10 +40,10 @@ function ble/keymap:vi_test/check { ((ntest++,nsuccess++)) else ((ntest++)) - echo "test($section/$id): keys = ($kspecs)" - echo " initial = \"$i:${in//$nl/$NL}\"" - echo " expected = \"$f:${fin//$nl/$NL}\"" - echo " result = \"$_ble_edit_ind:${_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"}\"" fi >&2 # restore states @@ -62,7 +62,7 @@ function ble/keymap:vi_test/show-summary { else local tip=$'\e[31mfailed\e[m' fi - echo "# $title test: result $((nsuccess))/$((ntest)) $tip" + ble/util/print "# $title test: result $((nsuccess))/$((ntest)) $tip" } #------------------------------------------------------------------------------ diff --git a/lib/core-complete.sh b/lib/core-complete.sh index 7191c400..8b2c1c36 100644 --- a/lib/core-complete.sh +++ b/lib/core-complete.sh @@ -3429,7 +3429,7 @@ function ble/complete/progcomp/.compgen { done [[ $has_desc ]] && bleopt complete_menu_style=desc else - [[ $progcomp_prefix ]] && cands=("${cands[@]/#/$progcomp_prefix}") # WA #D1570 safe + [[ $progcomp_prefix ]] && cands=("${cands[@]/#/"$progcomp_prefix"}") # WA #D1570 safe fi ble/complete/cand/yield.batch "$action" "$comp_opts" diff --git a/lib/core-syntax.sh b/lib/core-syntax.sh index e3214a24..f426ea42 100644 --- a/lib/core-syntax.sh +++ b/lib/core-syntax.sh @@ -973,14 +973,14 @@ function ble/syntax:bash/cclass/update { local histc2=${_ble_syntax_bash_histc12:1:1} for key in "${!_ble_syntax_bash_charsFmt[@]}"; do local a=${_ble_syntax_bash_charsFmt[key]} - a=${a//@h/$histc1} - a=${a//@q/$histc2} + a=${a//@h/"$histc1"} + a=${a//@q/"$histc2"} _ble_syntax_bash_chars[key]=$a done local a=$_ble_syntax_bash_chars_simpleFmt - a=${a//@h/$histc1} - a=${a//@q/$histc2} + a=${a//@h/"$histc1"} + a=${a//@q/"$histc2"} _ble_syntax_bashc_simple=$a fi @@ -2252,7 +2252,7 @@ function ble/syntax:bash/check-history-expansion/.initialize-event { local A="[$histc1]" [[ $histc1 == '^' ]] && A='\^' rex_event=$_ble_syntax_bash_histexpand_RexEventFmt - rex_event=${rex_event//@A/$A} + rex_event=${rex_event//@A/"$A"} fi } ## @fn ble/syntax:bash/check-history-expansion/.initialize-quicksub @@ -2263,8 +2263,8 @@ function ble/syntax:bash/check-history-expansion/.initialize-quicksub { rex_quicksub=$_ble_syntax_bash_histexpand_RexQuicksubDef else rex_quicksub=$_ble_syntax_bash_histexpand_RexQuicksubFmt - rex_quicksub=${rex_quicksub//@A/[$histc2]} - rex_quicksub=${rex_quicksub//@C/$histc2} + rex_quicksub=${rex_quicksub//@A/"[$histc2]"} + rex_quicksub=${rex_quicksub//@C/"$histc2"} fi } function ble/syntax:bash/check-history-expansion/.check-modifiers { @@ -4411,10 +4411,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"}" + b='\$' a='$'; str="${str//"$b"/"$a"}" + b='\\' a='\'; str="${str//"$b"/"$a"}" result=$result$str text=${text:${#BASH_REMATCH}} continue @@ -4450,12 +4450,12 @@ function ble/syntax:bash/ctx-heredoc-word/escape-delimiter { local ret=$1 if [[ $ret == *[\\\'$_ble_term_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 a81b9bc0..582f8726 100755 --- a/make_command.sh +++ b/make_command.sh @@ -1141,11 +1141,31 @@ function sub:scan/bash301bug-array-element-length { function sub:scan/bash501-arith-base { echo "--- $FUNCNAME ---" - # bash-3.1 で ${#arr[index]} を用いると、 - # 日本語の文字数が変になる。 + # bash-5.1 で $((10#)) の取り扱いが変わった。 grc '\b10#\$' --exclude={test,ChangeLog.md} } +function sub:scan/bash502-patsub_replacement { + echo "--- $FUNCNAME ---" + # bash-5.2 patsub_replacement で ${var/pat/string} の string 中の & が特別な + # 意味を持つ様になったので、特に意識する場合を除いては quote が必要になった。 + local esc='(\[[ -?]*[@-~])*' + grc --color '\$\{[[:alnum:]_]+(\[[^][]*\])?//?([^{}]|\{[^{}]*\})+/[^{}"'\'']*([&$]|\\)' --exclude=./test | + sed -E 'h;s/'"$esc"'//g;s/^[^:]*:[0-9]+:[[:space:]]*// + \Z//?\$q/\$Q\}Zd + \Z//?\$__ble_q/\$__ble_Q\}Zd + \Z//?\$_ble_local_q/\$_ble_local_Q\}Zd + \Z/\$\(\([^()]+\)\)\}Zd + \Z/\$'\''([^\\]|\\.)+'\''\}Zd + + \Z\$\{[a-zA-Z0-9_]+//(ARR|DICT|PREFIX|NAME)/\$([a-zA-Z0-9_]+|\{[a-zA-Z0-9_#:-]+\})\}Zd + \Z\$\{[a-zA-Z0-9_]+//'\''%[dlcxy]'\''/\$[a-zA-Z0-9_]+\}Zd # src/canvas.sh + + \Z#D1738Zd + \Z\$\{_ble_edit_str//\$'\''\\n'\''/\$'\''\\n'\''"\$comment_begin"\}Zd # edit.sh + g' +} + function sub:scan/gawk402bug-regex-check { echo "--- $FUNCNAME ---" grc --color '\[\^?\][^]]*\[:[^]]*:\].[^]]*\]' --exclude={test,ext,\*.md} | grep -Ev '#D1709 safe' @@ -1301,6 +1321,7 @@ function sub:scan { sub:scan/bash300bug sub:scan/bash301bug-array-element-length sub:scan/bash501-arith-base + sub:scan/bash502-patsub_replacement sub:scan/gawk402bug-regex-check sub:scan/array-count-in-arithmetic-expression sub:scan/unset-variable | diff --git a/memo/D1738.wa-old-patsub_replacement.patch b/memo/D1738.wa-old-patsub_replacement.patch new file mode 100644 index 00000000..81034084 --- /dev/null +++ b/memo/D1738.wa-old-patsub_replacement.patch @@ -0,0 +1,298 @@ +From e945e1f541b09b47db1353b0ebf001761cee40ef Mon Sep 17 00:00:00 2001 +From: Koichi Murase +Date: Thu, 13 Jan 2022 18:04:32 +0900 +Subject: [PATCH] [stub] global: work around bash-5.2a patsub_replacement + +--- + keymap/vi.sh | 8 ++- + lib/core-syntax.sh | 36 ++++++++------ + src/edit.sh | 12 +++-- + src/util.sh | 121 ++++++++++++++++++++++++++++++++++++--------- + 4 files changed, 133 insertions(+), 44 deletions(-) + +diff --git a/keymap/vi.sh b/keymap/vi.sh +index e586e54..f3824e0 100644 +--- a/keymap/vi.sh ++++ b/keymap/vi.sh +@@ -6971,7 +6971,13 @@ function ble/widget/vi_xmap/visual-replace-char.hook { + fi + + local ins=${_ble_edit_str:beg:end-beg} +- ins=${ins//[!$'\n']/"$s"} ++ if ((_ble_bash>=50200)) && shopt -q patsub_replacement; then ++ shopt -u patsub_replacement ++ ins=${ins//[!$'\n']/"$s"} ++ shopt -s patsub_replacement ++ else ++ ins=${ins//[!$'\n']/"$s"} ++ fi + ble/widget/.replace-range "$beg" "$end" "$ins" + ble/keymap:vi/needs-eol-fix "$beg" && ((beg--)) + _ble_edit_ind=$beg +diff --git a/lib/core-syntax.sh b/lib/core-syntax.sh +index e3214a2..00362f4 100644 +--- a/lib/core-syntax.sh ++++ b/lib/core-syntax.sh +@@ -972,16 +972,16 @@ function ble/syntax:bash/cclass/update { + local histc1=${_ble_syntax_bash_histc12:0:1} + local histc2=${_ble_syntax_bash_histc12:1:1} + for key in "${!_ble_syntax_bash_charsFmt[@]}"; do +- local a=${_ble_syntax_bash_charsFmt[key]} +- a=${a//@h/$histc1} +- a=${a//@q/$histc2} +- _ble_syntax_bash_chars[key]=$a ++ local ret=${_ble_syntax_bash_charsFmt[key]} ++ ble/string#replace "$ret" @h "$histc1" ++ ble/string#replace "$ret" @q "$histc2" ++ _ble_syntax_bash_chars[key]=$ret + done + +- local a=$_ble_syntax_bash_chars_simpleFmt +- a=${a//@h/$histc1} +- a=${a//@q/$histc2} +- _ble_syntax_bashc_simple=$a ++ local ret=$_ble_syntax_bash_chars_simpleFmt ++ ble/string#replace "$ret" @h "$histc1" ++ ble/string#replace "$ret" @q "$histc2" ++ _ble_syntax_bashc_simple=$ret + fi + + if [[ $seed == *x ]]; then +@@ -2251,8 +2251,9 @@ function ble/syntax:bash/check-history-expansion/.initialize-event { + else + local A="[$histc1]" + [[ $histc1 == '^' ]] && A='\^' +- rex_event=$_ble_syntax_bash_histexpand_RexEventFmt +- rex_event=${rex_event//@A/$A} ++ local ret=$_ble_syntax_bash_histexpand_RexEventFmt ++ ble/string#replace "$ret" @A "$A" ++ rex_event=$ret + fi + } + ## @fn ble/syntax:bash/check-history-expansion/.initialize-quicksub +@@ -2262,9 +2263,10 @@ function ble/syntax:bash/check-history-expansion/.initialize-quicksub { + if [[ $histc2 == '^' ]]; then + rex_quicksub=$_ble_syntax_bash_histexpand_RexQuicksubDef + else +- rex_quicksub=$_ble_syntax_bash_histexpand_RexQuicksubFmt +- rex_quicksub=${rex_quicksub//@A/[$histc2]} +- rex_quicksub=${rex_quicksub//@C/$histc2} ++ local ret=$_ble_syntax_bash_histexpand_RexQuicksubFmt ++ ble/string#replace "$ret" @A "[$histc2]" ++ ble/string#replace "$ret" @C "$histc2" ++ rex_quicksub=$ret + fi + } + function ble/syntax:bash/check-history-expansion/.check-modifiers { +@@ -4450,8 +4452,12 @@ function ble/syntax:bash/ctx-heredoc-word/escape-delimiter { + local ret=$1 + if [[ $ret == *[\\\'$_ble_term_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}" ++ if ((_ble_bash>=50200)) && shopt -q patsub_replacement; then ++ b='\\&'; ret="${ret//[\\\']/$b}" ++ else ++ a=\\ ; b="\\$a"; ret="${ret//"$a"/$b}" ++ a=\' ; b="\\$a"; ret="${ret//"$a"/$b}" ++ fi + 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}" +diff --git a/src/edit.sh b/src/edit.sh +index 4650217..bdee4e7 100644 +--- a/src/edit.sh ++++ b/src/edit.sh +@@ -601,10 +601,14 @@ _ble_prompt_term_status_data=() + function ble/prompt/print { + local text=$1 a b + if [[ ! $prompt_noesc && $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} ++ if ((_ble_bash>=50200)) && shopt -q patsub_replacement; then ++ text=${text//[\\\$\"\`]/\\\\&} ++ else ++ 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 + fi + ble/canvas/put.draw "$text" + } +diff --git a/src/util.sh b/src/util.sh +index 3a7c16a..6ce9e42 100644 +--- a/src/util.sh ++++ b/src/util.sh +@@ -115,7 +115,13 @@ function bleopt/.read-arguments { + + if [[ $op ]]; then + var=("${var[@]}") # #D1570: WA bash-3.0 ${scal[@]/x} bug +- ble/array#push specs "${var[@]/%/=$value}" # #D1570 WA checked ++ if ((_ble_bash>=50200)) && shopt -q patsub_replacement; then ++ shopt -u patsub_replacement ++ ble/array#push specs "${var[@]/%/=$value}" # #D1570 WA checked ++ shopt -s patsub_replacement ++ else ++ ble/array#push specs "${var[@]/%/=$value}" # #D1570 WA checked ++ fi + else + ble/array#push pvars "${var[@]}" + fi +@@ -771,11 +777,18 @@ function ble/array#replace { + } + + 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 +- builtin eval -- "${_ble_script//ARR/$1}" ++ if ((_ble_bash>=50200)) && shopt -q patsub_replacement; then ++ shopt -u patsub_replacement ++ ble/dense-array#fill-range "$@" ++ shopt -s patsub_replacement ++ return ++ else ++ 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 ++ builtin eval -- "${_ble_script//ARR/$1}" ++ fi + } + + function ble/idict#copy { +@@ -796,15 +809,48 @@ function ble/string#reserve-prototype { + done + } + ++## @fn ble/string#replace str before after ++## @param[in] str before after ++## @var[out] ret ++if ((_ble_bash>=50200)); then ++ function ble/string#replace { ++ if shopt -q patsub_replacement; then ++ shopt -u patsub_replacement ++ ret=${1//"$1"/$2} ++ shopt -s patsub_replacement ++ else ++ ret=${1//"$1"/$2} ++ fi ++ } ++else ++ function ble/string#replace { ++ ret=${1//"$1"/$2} ++ } ++fi ++ + ## @fn ble/string#repeat str count + ## @param[in] str + ## @param[in] count + ## @var[out] ret +-function ble/string#repeat { +- ble/string#reserve-prototype "$2" +- ret=${_ble_string_prototype::$2} +- ret="${ret// /$1}" +-} ++if ((_ble_bash>=50200)); then ++ function ble/string#repeat { ++ ble/string#reserve-prototype "$2" ++ ret=${_ble_string_prototype::$2} ++ if shopt -q patsub_replacement; then ++ shopt -u patsub_replacement ++ ret="${ret// /$1}" ++ shopt -s patsub_replacement ++ else ++ ret="${ret// /$1}" ++ fi ++ } ++else ++ function ble/string#repeat { ++ ble/string#reserve-prototype "$2" ++ ret=${_ble_string_prototype::$2} ++ ret="${ret// /$1}" ++ } ++fi + + ## @fn ble/string#common-prefix a b + ## @param[in] a b +@@ -1074,16 +1120,41 @@ function ble/string#rtrim { + ## @param[in] chars1 + ## @param[in,opt] chars2 + ## @var[out] ret +-function ble/string#escape-characters { +- ret=$1 +- if [[ $ret == *["$2"]* ]]; then +- local chars1=$2 chars2=${3:-$2} +- local i n=${#chars1} a b +- for ((i=0;i=50200)); then ++ function ble/string#escape-characters { ++ ret=$1 ++ if [[ $ret == *["$2"]* ]]; then ++ local patsub_replacement= ++ shopt -q patsub_replacement && patsub_replacement=1 ++ if [[ $3 ]]; then ++ shopt -s patsub_replacement ++ ret=${ret//["$2"]/\\\\&} ++ [[ $patsub_replacement ]] || ++ shopt -u patsub_replacement ++ else ++ shopt -u patsub_replacement ++ local chars1=$2 chars2=${3:-$2} ++ local i n=${#chars1} a b ++ for ((i=0;i&2 ++ local sgr=$1 message=${_ble_term_visible_bell_prev[1]} ret ++ ble/string#replace "$_ble_term_visible_bell_show" %message% "$sgr$message" ++ ble/util/put "$ret" >&2 + } + function ble/term/visible-bell:term/update { + ble/term/visible-bell:term/show "$@" +@@ -5619,7 +5691,8 @@ function ble/term/cursor-state/.update { + local state=$(($1)) + [[ $_ble_term_cursor_current == "$state" ]] && return 0 + +- local ret=${_ble_term_Ss//@1/$state} ++ local ret ++ ble/string#replace "$_ble_term_Ss" @1 "$state" + + # Note: 既に pass-through seq が含まれている時はスキップする。 + [[ $ret && $ret != $'\eP'*$'\e\\' ]] && +-- +2.33.1 + diff --git a/note.txt b/note.txt index b8f203e4..6b0b1aab 100644 --- a/note.txt +++ b/note.txt @@ -1688,6 +1688,17 @@ bash_tips ToDo ------------------------------------------------------------------------------- +2022-01-19 + + * PS1 のディレクトリ名に特殊文字が含まれている場合の取り扱い + https://lists.gnu.org/archive/html/bug-bash/2022-01/msg00051.html + + これは不要な互換性の問題を防ぐために Chet がどの様に対処するのかを見てから + それと同じ様に実装するのが良い。 + + またその他の文字列についても同様に注意が必要なのではないかと思われる。 + と思ったが他に任意の文字列を出力する様な状況もない様な気はする。 + 2022-01-08 * mandb: echo のオプションの抽出 (help echo) がおかしい at fc35 vm @@ -1705,6 +1716,8 @@ bash_tips (過去に承認したものは hash か或いは実体を記録しておいて再度尋ねはしない様に できる)。 + →direnv が丁度同じ事を目的としたプロジェクトの様である。 + 2021-12-20 * git-prompt, git-status 等の機能の模倣? @@ -5810,6 +5823,56 @@ bash_tips Done (実装ログ) ------------------------------------------------------------------------------- +2022-01-20 + + * 2022-01-13 bash-5.2 shopt patsub_replacement 対策 [#D1738] + + % 取り敢えず危なそうな箇所を抽出しておく。うーん。やはり可也面倒である。 + % ble/string#replace 等の関数を作るべきなのかもしれない。 + % + % $ grc '\$\{[[:alnum:]_]+(\[[^][]*\])?/' --exclude={memo,test,wiki} + % $ grc '\$\{[[:alnum:]_]+(\[[^][]*\])?//?[^{}]*/[^{}]*[$&]' + % $ grc '\$\{[[:alnum:]_]+(\[[^][]*\])?//?([^{}]|\{[^{}]*\})+/[^{}]*([$&]|\\)' + % + % done: ./keymap/vi.sh:6974: ins=${ins//[!$'\n']/"$s"} ★ + % done: ./lib/core-syntax.sh:976: a=${a//@h/$histc1} + % done: ./lib/core-syntax.sh:977: a=${a//@q/$histc2} + % done: ./lib/core-syntax.sh:982: a=${a//@h/$histc1} + % done: ./lib/core-syntax.sh:983: a=${a//@q/$histc2} + % done: ./lib/core-syntax.sh:2255: rex_event=${rex_event//@A/$A} + % done: ./lib/core-syntax.sh:2266: rex_quicksub=${rex_quicksub//@A/[$histc2]} + % done: ./lib/core-syntax.sh:2267: rex_quicksub=${rex_quicksub//@C/$histc2} + % done: ./lib/core-syntax.sh:4453: a=\\ ; b="\\$a"; ret="${ret//"$a"/$b}" ★ + % done: ./src/edit.sh:604: a='\' b='\\' text=${text//"$a"/$b} ★ + % done: ./src/util.sh:118: ble/array#push specs "${var[@]/%/=$value}" # #D1570 WA checked + % done: ./src/util.sh:777: ARR=("${ARR[@]::$2}" "${sARR[@]/#/$4}" "${ARR[@]:$3}")' # WA #D1570 checked + % done: ./src/util.sh:806: ret="${ret// /$1}" + % done: ./src/util.sh:1083: a=${chars1:i:1} b=\\${chars2:i:1} ret=${ret//"$a"/$b} + % done: ./src/util.sh:5305: ble/util/put "${_ble_term_visible_bell_show//'%message%'/$sgr$message}" >&2 + % done: ./src/util.sh:5622: local ret=${_ble_term_Ss//@1/$state} + % + % ????: ./src/util.sh:1379: builtin eval -- "${_ble_local_script//opts/$1}" # Note: 配列要素に変な文字が入っていると駄目 + % ????: ./src/util.sh:1383: builtin eval -- "${_ble_local_script//opts/$1}" # Note: 配列要素に変な文字が入っていると駄目 + % ????: ./src/util.sh:1391: builtin eval -- "${_ble_local_script//opts/$1}" # Note: 配列要素に変な文字が入っていると駄目 + % ????: ./src/util.sh:1399: builtin eval -- "${_ble_local_script//opts/$1}" # Note: 配列要素に変な文字が入っていると駄目 + % →うーん。これらについては元々配列要素を想定していない実装になっているのでここで改めて気にするのも変である。 + % それに配列要素を想定している場合には添字は先に1回だけ評価するべきの気がする。なので、そんなに単純ではない。 + % これは今回は見送り。 + % + % ok: ./src/util.sh:1516: builtin eval -- "${_ble_local_script//NAME/$1}" + % ok: ./src/util.sh:1899:builtin eval -- "${_ble_util_gdict_declare//NAME/_ble_builtin_trap_n2i}" + % ok: ./src/util.sh:2515: builtin eval -- "${_ble_local_script//ARR/$_ble_local_array}" + + 外部プロジェクトも気になる。うーん。これは悲惨な結果である。 + bashdb, bash-completion, etc. が大抵影響を受ける様に見える。 + -> bug-report bash/report31/affected.txt に移した。 + + bug-bash に再度報告した。結局、当初の提案で実装し直して貰った。 + + 改めて新しい実装に合わせて ble.sh を調整する事にした。改めて丁寧にチェック + を行って行ったところ、先の修正で見過ごしていた所も幾らか見つかった。自動検 + 出しやすい様にスタイルを統一し、その上で自動検出を記述した。 + 2022-01-18 * ble-measure の base がやはりずれる。より良い更新式を取得したい [#D1737] diff --git a/src/canvas.sh b/src/canvas.sh index f7b7b92d..35b731c1 100644 --- a/src/canvas.sh +++ b/src/canvas.sh @@ -894,10 +894,10 @@ function ble/canvas/put-vpa.draw { function ble/canvas/put-ech.draw { local value=${1:-1} esc if [[ $_ble_term_ech ]]; then - esc=${_ble_term_ech/'%d'/$value} + esc=${_ble_term_ech//'%d'/$value} else ble/string#reserve-prototype "$value" - esc=${_ble_string_prototype::value}${_ble_term_cub/'%d'/$value} + esc=${_ble_string_prototype::value}${_ble_term_cub//'%d'/$value} fi DRAW_BUFF[${#DRAW_BUFF[*]}]=$esc } diff --git a/src/decode.sh b/src/decode.sh index 648311c6..5e0323e6 100644 --- a/src/decode.sh +++ b/src/decode.sh @@ -3517,10 +3517,10 @@ function ble/builtin/bind/rlfunc2widget { if [[ $rlfunc_file ]]; then local dict script=' - ((${#RLFUNC_DICT[@]})) || - ble/util/mapfile RLFUNC_DICT < "$rlfunc_file" - dict=("${RLFUNC_DICT[@]}")' - builtin eval -- "${script//RLFUNC_DICT/$rlfunc_dict}" + ((${#DICT[@]})) || + ble/util/mapfile DICT < "$rlfunc_file" + dict=("${DICT[@]}")' + builtin eval -- "${script//DICT/$rlfunc_dict}" local line TMOUT= 2>/dev/null # #D1630 WA readonly TMOUT for line in "${dict[@]}"; do diff --git a/src/edit.sh b/src/edit.sh index 46502173..60f50be1 100644 --- a/src/edit.sh +++ b/src/edit.sh @@ -427,7 +427,7 @@ function ble/prompt/initialize { c=$ret fi fi - windir=/cygdrive/$c/${path//$bsl/$sl} + windir=/cygdrive/$c/${path//"$bsl"/"$sl"} fi if [[ -e $windir && -w $windir ]]; then @@ -599,14 +599,10 @@ _ble_prompt_term_status_data=() ## @var[out] DRAW_BUFF[] ## 出力先の配列です。 function ble/prompt/print { - local text=$1 a b - if [[ ! $prompt_noesc && $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 a b + [[ $prompt_noesc ]] || + ble/string#escape-characters "$ret" '$\"`' + ble/canvas/put.draw "$ret" } ## @fn ble/prompt/process-prompt-string prompt_string diff --git a/src/history.sh b/src/history.sh index 23800007..5ae78039 100644 --- a/src/history.sh +++ b/src/history.sh @@ -1109,7 +1109,7 @@ function ble/builtin/history/array#delete-hindex { local script=' local -a out=() local i shift=0 - for i in "${!ARRAY[@]}"; do + for i in "${!ARR[@]}"; do local delete= while (($#)); do if [[ $1 == *-* ]]; then @@ -1130,11 +1130,11 @@ function ble/builtin/history/array#delete-hindex { fi done [[ ! $delete ]] && - out[i-shift]=${ARRAY[i]} + out[i-shift]=${ARR[i]} done - ARRAY=() - for i in "${!out[@]}"; do ARRAY[i]=${out[i]}; done' - builtin eval -- "${script//ARRAY/$array_name}" + ARR=() + for i in "${!out[@]}"; do ARR[i]=${out[i]}; done' + builtin eval -- "${script//ARR/$array_name}" } ## @fn ble/builtin/history/array#insert-range array_name beg len function ble/builtin/history/array#insert-range { @@ -1142,12 +1142,12 @@ function ble/builtin/history/array#insert-range { local script=' local -a out=() local i - for i in "${!ARRAY[@]}"; do - out[i=50200)); then + function ble/string#escape-characters { + ret=$1 + if [[ $ret == *["$2"]* ]]; then + if [[ ! $3 ]]; then + local patsub_replacement= + shopt -q patsub_replacement && patsub_replacement=1 + shopt -s patsub_replacement + ret=${ret//["$2"]/\\&} # #D1738 patsub_replacement + [[ $patsub_replacement ]] || shopt -u patsub_replacement + else + local chars1=$2 chars2=${3:-$2} + local i n=${#chars1} a b + for ((i=0;i=40000)); then else _ble_util_set_declare=(declare NAME) function ble/set#.escape { - _ble_local_value=${_ble_local_value//$_ble_term_FS/$_ble_term_FS$_ble_term_FS} - _ble_local_value=${_ble_local_value//:/$_ble_term_FS.} + _ble_local_value=${_ble_local_value//$_ble_term_FS/"$_ble_term_FS$_ble_term_FS"} + _ble_local_value=${_ble_local_value//:/"$_ble_term_FS."} } function ble/set#add { local _ble_local_value=$2; ble/set#.escape @@ -1490,8 +1512,8 @@ _ble_util_adict_declare='declare NAME NAME_keylist' function ble/adict#.resolve { # _ble_local_key _ble_local_key=$2 - _ble_local_key=${_ble_local_key//$_ble_term_FS/$_ble_term_FS,} - _ble_local_key=${_ble_local_key//:/$_ble_term_FS.} + _ble_local_key=${_ble_local_key//$_ble_term_FS/"$_ble_term_FS,"} + _ble_local_key=${_ble_local_key//:/"$_ble_term_FS."} local keylist=${1}_keylist; keylist=:${!keylist} local vec=${keylist%%:"$_ble_local_key":*} @@ -1548,8 +1570,8 @@ function ble/adict#keys { _ble_local_keylist=${!_ble_local_keylist%:} ble/string#split ret : "$_ble_local_keylist" if [[ $_ble_local_keylist == *"$_ble_term_FS"* ]]; then - ret=("${ret[@]//$_ble_term_FS./:}") # WA #D1570 checked - ret=("${ret[@]//$_ble_term_FS,/$_ble_term_FS}") # WA #D1570 checked + ret=("${ret[@]//$_ble_term_FS./:}") # WA #D1570 checked + ret=("${ret[@]//$_ble_term_FS,/"$_ble_term_FS"}") # WA #D1570 checked fi # filter out unset elements @@ -5302,7 +5324,7 @@ function ble/term/visible-bell:term/init { } function ble/term/visible-bell:term/show { local sgr=$1 message=${_ble_term_visible_bell_prev[1]} - ble/util/put "${_ble_term_visible_bell_show//'%message%'/$sgr$message}" >&2 + ble/util/put "${_ble_term_visible_bell_show//'%message%'/"$sgr$message"}" >&2 } function ble/term/visible-bell:term/update { ble/term/visible-bell:term/show "$@" @@ -5619,7 +5641,7 @@ function ble/term/cursor-state/.update { local state=$(($1)) [[ $_ble_term_cursor_current == "$state" ]] && return 0 - local ret=${_ble_term_Ss//@1/$state} + local ret=${_ble_term_Ss//@1/"$state"} # Note: 既に pass-through seq が含まれている時はスキップする。 [[ $ret && $ret != $'\eP'*$'\e\\' ]] &&