From 557b77470758fa0432413a21c60e4d78e784e809 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Fri, 10 Apr 2020 20:57:36 +0900 Subject: [PATCH] test: work around miscllaneous compatibility issues --- lib/core-complete.sh | 2 +- memo/ChangeLog.md | 15 +++++++++++---- note.txt | 40 ++++++++++++++++++++++++++++++++++------ src/decode.sh | 8 ++++---- src/util.sh | 8 ++++++-- 5 files changed, 56 insertions(+), 17 deletions(-) diff --git a/lib/core-complete.sh b/lib/core-complete.sh index 0bd2b96a..591efadf 100644 --- a/lib/core-complete.sh +++ b/lib/core-complete.sh @@ -4317,7 +4317,7 @@ function ble/complete/menu-filter { ble/syntax:bash/simple-word/is-never-word "$input" && return 1 return 0 fi - [[ $simple_ibrace ]] && ((${simple_ibrace%%:*}>10#${_ble_complete_menu0_comp[6]%%:*})) && return 1 # 別のブレース展開要素に入った時 + [[ $simple_ibrace ]] && ((${simple_ibrace%%:*}>10#0${_ble_complete_menu0_comp[6]%%:*})) && return 1 # 別のブレース展開要素に入った時 ble/syntax:bash/simple-word/eval "$ret" local COMPV=$ret diff --git a/memo/ChangeLog.md b/memo/ChangeLog.md index 7d5ca0eb..ad27cea6 100644 --- a/memo/ChangeLog.md +++ b/memo/ChangeLog.md @@ -16,7 +16,7 @@ - syntax: support parameter expansion of the form `${var/#pat}`, `${var/%pat}` `#D1286` e2f4809 - edit: support `bleopt editor line_limit_{type,length} history_limit_length` `#D1295` 2f9a000 - edit: support widgets `{vi,emacs}-editing-mode` `#D1301` 0c6c76e -- syntax: allow unquoted `[!` and `[^` in `simple-word` (reported by cmplstofB) `#D1303` 0000000 +- syntax: allow unquoted `[!` and `[^` in `simple-word` (reported by cmplstofB) `#D1303` 1efe833 ## Fix @@ -52,6 +52,13 @@ - util: fix `ble/is-{inttype,readonly,transformed}` (test-util) 485e1ac - util (`ble/path#remove{,-glob}`): fix corner cases (test-util) ccbc9f8 - history: fix a problem that the history is doubled by `history -a` in `bashrc` `#D1314` 34821fe +- decode: work around Bash-4.1 bug that locale not applied with `LC_CTYPE=C eval command` b2c7d1c +- util (`ble/variable#get-attr`): fix a bug that attributes are not obtained in Bash <= 4.3 b2c7d1c +- decode: work around Bash-3.1 bug of `declare -f` rejecting special characters in function names b2c7d1c +- edit (`ble/widget/bracketed-paste`): fix error messages on `paste_end` in older version of Bash b2c7d1c +- decode: work around Bash-4.1 arithmetic bug of array subscripts evaluated in discarded branches `#D1320` 0000000 +- util (`ble/variable#get-attr`): fix an error message with special variable names such as `?` and `*` `#D1321` 0000000 +- complete: follow Bash-5.1 change of arithmetic literal `10#` `#D1322` 0000000 ## Changes @@ -102,9 +109,9 @@ - test: add `lib/core-test.sh` `#D1309` 68f8077 - global: do not use `local -i` `#D1310` f9f0f9b - global: normalize calls of builtins `#D1313` b3b06f7 -- test: refactor test `#D1316` `#D1317` 0000000 -- util (`ble/util/openat`): change to open unused fds `#D1318` 0000000 -- util: rename `ble/{util/openat => fd#alloc}` `#D1319` 0000000 +- test: refactor test `#D1316` `#D1317` 6c2f863 +- util (`ble/util/openat`): change to open unused fds `#D1318` 6c2f863 +- util: rename `ble/{util/openat => fd#alloc}` `#D1319` 6c2f863 # ble-0.4.0-devel1 diff --git a/note.txt b/note.txt index 66dca017..13c0ac7f 100644 --- a/note.txt +++ b/note.txt @@ -540,6 +540,10 @@ bashbug 算術式周りのバグと注意点 $ expr="a=1,x=dbg[0],b=1"; ((a=0,b=0,0&&expr)); echo $a $b → 0 1 $ expr="a=1,x=dbg[0],b=1"; ((a=0,b=0,0&&(expr))); echo $a $b → 0 1 + 更に配列添字も必ず評価されてしまう。 + ((i>=0&&a[i])) は i が負であっても参照される。 + そして、((i>=0&&a[i--])) をすると更に副作用も起こる。 + * bash-4.1 以下 (bash-3.0 ~ bash-4.1) 配列要素に対して修飾付きのパラメータ展開を実行すると、 @@ -1007,13 +1011,14 @@ bash_tips 2020-04-09 - * complete: bash-dev で 10# のエラーが出ている。 - "0>10#: invalid integer constant (エラーのあるトークンは "10#")" - - * failglob: bash-4.3 で $? を入力するとエラーメッセージが出る。 + * syntax: ${#@a} の着色 + どうも $@ に修飾 # とごみ a がついていると解析している気がする。 + 然し、実際には $# に修飾 @a がついていると解釈するべきである。 + 他に ${##0} もエラー着色になっている。 + これは ${##} に 0 がついているという具合に解釈されている気がするが + 実際には $# に #0 という修飾がついているという様に + 解釈しなければならないのである。 - * _ble_decode_input_buffer で不正な添字というエラーが発生する。 - * 別の bash の枠組みについて https://github.com/sio/bash-complete-partial-path https://github.com/mgalgs/fuzzy_bash_completion @@ -2865,6 +2870,29 @@ bash_tips Done (実装ログ) ------------------------------------------------------------------------------- +2020-04-10 + + * complete: bash-dev で 10# のエラーが出ている [#D1322] + "0>10#: invalid integer constant (エラーのあるトークンは "10#")" + →これは簡単に修正できた。一箇所しか 10# はなかった。 + + * failglob: bash-4.3 で $? を入力するとエラーメッセージが出る [#D1321] + syntax highlighting が効いているのに違いないという気がする。 + 特に変数の内容を調べるコードが怪しい気がする。 + うーん。get-attr だろうか→正にそれである。 + これは直った。 + + * _ble_decode_input_buffer で不正な添字というエラーが発生する [#D1320] + bash-4.1 以下で発生する様である。 + うーん。((i=-1,i>=0&&a[i--])) が bash-4.1 以下で駄目の様である。 + うーん。これは算術式のバグである。今まで知らなかったバグだ。 + →と思って確認したら既に分岐内の配列参照は実行されるという事が書かれている。 + 唯、それが配列添字の中でも起こるという事は新たな発見であった。 + + 一応類似の物が存在しないか確認する。 + grc '(\|\||\?|&&)[[:alnum:]_]+\[' + 取り敢えずは問題無さそうである。 + 2020-04-09 * ble/util/openat は関数名を変更するべきでは [#D1319] diff --git a/src/decode.sh b/src/decode.sh index 4ac213ba..b770dad3 100644 --- a/src/decode.sh +++ b/src/decode.sh @@ -523,7 +523,7 @@ function ble-decode/.check-abort { # Check code for ((;n;n/=10)); do - ((i>=0&&_ble_decode_input_buffer[i--]==n%10+48)) || return 1 + ((i>=0)) && ((_ble_decode_input_buffer[i--]==n%10+48)) || return 1 done # Check "27;5;" @@ -544,12 +544,12 @@ function ble-decode/.check-abort { # Check code for ((;n;n/=10)); do - ((i>=0&&_ble_decode_input_buffer[i--]==n%10+48)) || return 1 + ((i>=0)) && ((_ble_decode_input_buffer[i--]==n%10+48)) || return 1 done fi # Skip ">" - ((i>=0&&_ble_decode_input_buffer[i]==62&&i--)) + ((i>=0)) && ((_ble_decode_input_buffer[i]==62&&i--)) # Check CSI ("\e[", "\xC0\x9B[" or "\xC2\x9B") # ENCODING: UTF-8 (\xC0\x9B) @@ -563,7 +563,7 @@ function ble-decode/.check-abort { return 1 fi elif ((_ble_decode_input_buffer[i]==0x9B)); then - ((--i>=0&&_ble_decode_input_buffer[i--]==0xC2)) || return 1 + ((--i>=0)) && ((_ble_decode_input_buffer[i--]==0xC2)) || return 1 else return 1 fi diff --git a/src/util.sh b/src/util.sh index 3d53cbbd..9cf0fc49 100644 --- a/src/util.sh +++ b/src/util.sh @@ -311,14 +311,18 @@ function ble/debug/print-variables { # variable, array and strings # +## 関数 ble/variable#get-attr varname +## 指定した変数の属性を取得します。 +## @var[out] attr if ((_ble_bash>=40400)); then function ble/variable#get-attr { attr=${!1@a}; } else function ble/variable#get-attr { attr= - local ret; ble/util/assign ret "declare -p $1 2>/dev/null" + local __tmp=$1 + ble/util/assign __tmp 'declare -p "$__tmp" 2>/dev/null' local rex='^declare -([a-zA-Z]*)' - [[ $ret =~ $rex ]] && attr=${BASH_REMATCH[1]} + [[ $__tmp =~ $rex ]] && attr=${BASH_REMATCH[1]} return 0 } fi