Skip to content

Commit

Permalink
global: fix bugs of the adjustments for bash-5.2 "patsub_replacement"…
Browse files Browse the repository at this point in the history
… (fixup 4590997)

* global: work around compat42 quoting of "${v/pat/"$rep"}" #D1751
* prompt: fix a bug of ble/prompt/print redundantly quoting '$' #D1752
* global: identify bash-4.2 bug that internal quoting of ${v/%$empty/"$rep"} remains #D1753
* global: work around "shopt -s compat42" #D1754
  • Loading branch information
akinomyoga committed Jul 28, 2022
1 parent 19fa092 commit e7adfb3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
20 changes: 14 additions & 6 deletions ble-core.sh
Expand Up @@ -171,7 +171,9 @@ function ble/dense-array#fill-range {
_ble_util_array_prototype.reserve $(($3-$2))
local _ble_script='
local -a sARR; sARR=("${_ble_util_array_prototype[@]::$3-$2}")
ARR=("${ARR[@]::$2}" "${sARR[@]/#/"$4"}" "${ARR[@]:$3}")' # WA #D1570 checked
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}"
}

Expand All @@ -190,7 +192,7 @@ function _ble_util_string_prototype.reserve {
function ble/string#repeat {
_ble_util_string_prototype.reserve "$2"
ret=${_ble_util_string_prototype::$2}
ret=${ret//' '/"$1"}
ret=${ret// /"$1"}
}

## 関数 ble/string#common-prefix a b
Expand Down Expand Up @@ -420,14 +422,20 @@ function ble/string#escape-for-extended-regex {
fi
}

function ble/util/strlen {
function ble/util/strlen.impl {
local LC_ALL= LC_CTYPE=C
ret=${#1}
} 2>/dev/null
function ble/util/substr {
}
function ble/util/strlen {
ble/util/strlen.impl "$@" 2>/dev/null
}
function ble/util/substr.impl {
local LC_ALL= LC_CTYPE=C
ret=${1:$2:$3}
} 2>/dev/null
}
function ble/util/substr {
ble/util/substr.impl "$@" 2>/dev/null # suppress locale error #D1440
}

## 関数 ble/builtin/trap/set-readline-signal sig handler
## ble.sh 内部で使用するハンドラを登録します。
Expand Down
2 changes: 1 addition & 1 deletion ble-decode.sh
Expand Up @@ -1644,7 +1644,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"';
Expand Down
9 changes: 6 additions & 3 deletions keymap/vi_test.sh
Expand Up @@ -31,10 +31,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
Expand Down
20 changes: 10 additions & 10 deletions lib/core-syntax.sh
Expand Up @@ -3311,10 +3311,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
Expand Down Expand Up @@ -3350,12 +3350,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
}
Expand Down

0 comments on commit e7adfb3

Please sign in to comment.