Skip to content

Commit

Permalink
decode (rlfunc): work around incomplete bytes in keyseq
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Feb 21, 2021
1 parent 3588158 commit 3559658
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
3 changes: 2 additions & 1 deletion memo/ChangeLog.md
Expand Up @@ -52,7 +52,8 @@
- global: fix declaration of associative arrays for `ble-reload` (reported by 0xC0ncord) `#D1471` 3cae6e4
- bind: work around broken `cmd_xmap` after switching the editing mode `#D1478` 8d354c1
- edit: clear graphic rendition on newlines and external commands `#D1479` 18bb2d5
- mandb: improve extraction and cache for each locale `#D1480` 0000000
- mandb: improve extraction and cache for each locale `#D1480` 3588158
- decode (rlfunc): work around incomplete bytes in keyseq (reported by onelittlehope) `#D1483` 0000000

## Internal changes and fixes

Expand Down
38 changes: 38 additions & 0 deletions note.txt
Expand Up @@ -3728,6 +3728,44 @@ bash_tips
Done (実装ログ)
-------------------------------------------------------------------------------

2021-02-21

* decode (rlfunc): 既存の束縛の読み取り時にエラー (reported by onelittlehope) [#D1483]
https://github.com/akinomyoga/ble.sh/issues/89

二種類の問題がある。

* 一つは LC_CTYPE であろう。現在のエンコーディングに一致しないバイト列が文
字列に含まれている場合、bash の正規表現は一致に失敗する。もしくは何か変な
一致の仕方をする。

$ alpha=$'"\x9B": self-insert'
$ rex='^"[^"]*$'
$ [[ $alpha =~ $rex ]]

然し実際に試してみたがそんな事は起こっていない。susu-linux の regcmop は
振る舞いが違うという事なのだろうか。これについては no closing ... という
メッセージを出している部分をもう少し詳しく見る必要がある。

* もう一つは vi_imap/vi_nmap で vi-replace/vi-editing-mode に対応していない
という事。これは単に対応していないというだけの事なのでできるだけ対応する
様にする。

然し、以下は期待通りに動いている。

rex='^"([^\"]|\\.)*$'
[[ $'"\x9B": self-insert' =~ $rex ]]; echo $?

できた。再現できた。

bind '"\x9b1;2H": beginning-of-line'
source ble.sh

更に良くメッセージを見ると正規表現でテストを実行する前に既に文字列が削れ
て '"' だけになっている。

→これについては修正した。

2021-02-20

* complete/mabdb: man awk の内容を抽出しきれていない [#D1480]
Expand Down
2 changes: 2 additions & 0 deletions src/decode.sh
Expand Up @@ -3174,6 +3174,7 @@ function ble/builtin/bind/option:m {
## keyseq:command の形式の文字列を keyseq と command に分離します。
## @var[out] keyseq value
function ble/builtin/bind/.decompose-pair {
local LC_ALL= LC_CTYPE=C
local ret; ble/string#trim "$1"
local spec=$ret ifs=$' \t\n' q=\' Q="'\''"
keyseq= value=
Expand Down Expand Up @@ -3210,6 +3211,7 @@ function ble/builtin/bind/.decompose-pair {
return 0
fi
}
ble/function#suppress-stderr ble/builtin/bind/.decompose-pair
## @fn ble/builtin/bind/.parse-keyname keyname
## @var[out] chars
function ble/builtin/bind/.parse-keyname {
Expand Down
10 changes: 7 additions & 3 deletions src/util.sh
Expand Up @@ -5022,12 +5022,16 @@ function ble/util/keyseq2chars {
local -a chars=()
local mods=
local rex='^([^\]+)|^\\([CM]-|[0-7]{1,3}|x[0-9a-fA-F]{1,2}|.)?'
while [[ $keyseq =~ $rex ]]; do
local text=${BASH_REMATCH[1]} esc=${BASH_REMATCH[2]}
keyseq=${keyseq:${#BASH_REMATCH}}
while [[ $keyseq ]]; do
local text=${keyseq::1}
[[ $keyseq =~ $rex ]] &&
text=${BASH_REMATCH[1]} esc=${BASH_REMATCH[2]}

if [[ $text ]]; then
keyseq=${keyseq:${#text}}
ble/util/s2chars "$text"
else
keyseq=${keyseq:$1+{#esc}}
ret=()
case $esc in
([CM]-) mods=$mods${esc::1}; continue ;;
Expand Down

0 comments on commit 3559658

Please sign in to comment.