Skip to content

Commit

Permalink
global: adjust implementations for bash-5.2 "patsub_replacement"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Jan 20, 2022
1 parent ad866c1 commit 4590997
Show file tree
Hide file tree
Showing 13 changed files with 492 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .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
Expand Down
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions keymap/vi_test.sh
Expand Up @@ -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
Expand All @@ -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"
}

#------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion lib/core-complete.sh
Expand Up @@ -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"

Expand Down
34 changes: 17 additions & 17 deletions lib/core-syntax.sh
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
25 changes: 23 additions & 2 deletions make_command.sh
Expand Up @@ -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'
Expand Down Expand Up @@ -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 |
Expand Down

0 comments on commit 4590997

Please sign in to comment.