Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
decode, canvas, etc.: fix "10#" errors on empty CSI parameter in Bash…
… 5.1 (fixup c6473b7)
  • Loading branch information
akinomyoga committed Jul 13, 2021
1 parent 3e4ecf5 commit 2ea48d7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion memo/ChangeLog.md
Expand Up @@ -144,7 +144,7 @@
- util: work around the Bash 3 bug of array assignments with `^A` and `^?` in Bash 3.2 `#D1614` b9f7611
- benchmark (`ble-measure`): fix a bug that the result is always 0 in Bash 3 and 4 (fixup bbc2a904) `#D1615` a034c91
- complete: fix a bug that the shopt settings are not restored correctly (reported by Lun4m) `#D1623` 899c114
- decode, canvas, etc.: explicitly treat CSI arguments as decimal numbers (reported by GorrillaRibs) `#D1625` c6473b7
- decode, canvas, etc.: explicitly treat CSI arguments as decimal numbers (reported by GorrillaRibs) `#D1625` c6473b7 0000000

## Optimization

Expand Down
5 changes: 5 additions & 0 deletions note.txt
Expand Up @@ -4705,6 +4705,11 @@ bash_tips
* ble/canvas/trace の諸々の制御機能についても対策した。
* SGR の解析部分 (ble/color/read-sgrspec) は既に対処済みだった

https://github.com/akinomyoga/ble.sh/issues/128#issuecomment-878670622

追加修正。10# で後ろに何も数字が続いていないと 5.1 ではエラーになる。
これは修正した。多分大丈夫。

2021-07-12

* emacs モードで vi-bword 使う (requested by SolarAquarion) [#D1624]
Expand Down
4 changes: 2 additions & 2 deletions src/canvas.sh
Expand Up @@ -1128,7 +1128,7 @@ function ble/canvas/trace/.process-csi-sequence {
return 0 ;;
([ABCDEFGIZ\`ade])
local arg=0
[[ $param =~ ^[0-9]+$ ]] && ((arg=10#$param))
[[ $param =~ ^[0-9]+$ ]] && ((arg=10#${param:-0}))
((arg==0&&(arg=1)))

local ox=$x oy=$y
Expand Down Expand Up @@ -1212,7 +1212,7 @@ function ble/canvas/trace/.process-csi-sequence {
# HVP "CSI f"
local -a params
ble/string#split-words params "${param//[^0-9]/ }"
params=("${params[@]/#/10#}")
params=("${params[@]/#/10#0}") # #D1570 is-array OK
local dstx dsty
((dstx=params[1]-1))
((dsty=params[0]-1))
Expand Down
30 changes: 15 additions & 15 deletions src/decode.sh
Expand Up @@ -839,8 +839,8 @@ function ble-decode-char/csi/.decode {
if ((char==126)); then # ~
if rex='^>?27;([0-9]+);?([0-9]+)$' && [[ $_ble_decode_csi_args =~ $rex ]]; then
# xterm "CSI 2 7 ; <mod> ; <char> ~" sequences
local param1=$((10#${BASH_REMATCH[1]}))
local param2=$((10#${BASH_REMATCH[2]}))
local param1=$((10#${BASH_REMATCH[1]:-0}))
local param2=$((10#${BASH_REMATCH[2]:-0}))
local key=$((param2&_ble_decode_MaskChar))
ble-decode-char/csi/.modify-key "$param1"
csistat=$key
Expand All @@ -849,8 +849,8 @@ function ble-decode-char/csi/.decode {

if rex='^>?([0-9]+)(;([0-9]+))?$' && [[ $_ble_decode_csi_args =~ $rex ]]; then
# "CSI <key> ; <mod> ~" sequences
local param1=$((10#${BASH_REMATCH[1]}))
local param3=$((10#${BASH_REMATCH[3]}))
local param1=$((10#${BASH_REMATCH[1]:-0}))
local param3=$((10#${BASH_REMATCH[3]:-0}))
key=${_ble_decode_csimap_tilde[param1]}
if [[ $key ]]; then
ble-decode-char/csi/.modify-key "$param3"
Expand All @@ -864,7 +864,7 @@ function ble-decode-char/csi/.decode {
# Note: 実は "CSI 1 ; mod u" が kp5 とする端末がある事に注意する。
local rematch1=${BASH_REMATCH[1]}
if [[ $rematch1 != 1 ]]; then
local key=$((10#$rematch1)) mods=$((10#${BASH_REMATCH:${#rematch1}+1}))
local key=$((10#${rematch1:-0})) mods=$((10#0${BASH_REMATCH:${#rematch1}+1}))
[[ $_ble_term_TERM == kitty ]] && ble-decode/char/csi/.translate-kitty-csi-u
ble-decode-char/csi/.modify-key "$mods"
csistat=$key
Expand All @@ -874,8 +874,8 @@ function ble-decode-char/csi/.decode {
elif ((char==94||char==64)); then # ^, @
if rex='^[0-9]+$' && [[ $_ble_decode_csi_args =~ $rex ]]; then
# rxvt "CSI <key> ^", "CSI <key> @" sequences
local param1=$((10#${BASH_REMATCH[1]}))
local param3=$((10#${BASH_REMATCH[3]}))
local param1=$((10#${BASH_REMATCH[1]:-0}))
local param3=$((10#${BASH_REMATCH[3]:-0}))
key=${_ble_decode_csimap_tilde[param1]}
if [[ $key ]]; then
((key|=_ble_decode_Ctrl,
Expand All @@ -901,8 +901,8 @@ function ble-decode-char/csi/.decode {
if rex='^([0-9]+);([0-9]+)$'; [[ $_ble_decode_csi_args =~ $rex ]]; then
# DSR(6) に対する応答 CPR "CSI Pn ; Pn R"
# Note: Poderosa は DSR(Pn;Pn) "CSI Pn ; Pn n" で返す。
local param1=$((10#${BASH_REMATCH[1]}))
local param2=$((10#${BASH_REMATCH[2]}))
local param1=$((10#${BASH_REMATCH[1]:-0}))
local param2=$((10#${BASH_REMATCH[2]:-0}))
ble/term/CPR/notify "$param1" "$param2"
csistat=$_ble_decode_KCODE_IGNORE
return 0
Expand All @@ -919,9 +919,9 @@ function ble-decode-char/csi/.decode {
# mouse1up mouse2up mouse3up mouse4up mouse5up
# mouse1drag mouse2drag mouse3drag mouse4drag mouse5drag
# wheelup wheeldown mouse_move
local param1=$((10#${BASH_REMATCH[1]}))
local param2=$((10#${BASH_REMATCH[2]}))
local param3=$((10#${BASH_REMATCH[3]}))
local param1=$((10#${BASH_REMATCH[1]:-0}))
local param2=$((10#${BASH_REMATCH[2]:-0}))
local param3=$((10#${BASH_REMATCH[3]:-0}))
local button=$param1
((_ble_term_mouse_button=button&~0x1C,
char==109&&(_ble_term_mouse_button|=0x70),
Expand All @@ -936,8 +936,8 @@ function ble-decode-char/csi/.decode {
elif ((char==116)); then # t
if rex='^<([0-9]+);([0-9]+)$'; [[ $_ble_decode_csi_args =~ $rex ]]; then
## mouse_select
local param1=$((10#${BASH_REMATCH[1]}))
local param2=$((10#${BASH_REMATCH[2]}))
local param1=$((10#${BASH_REMATCH[1]:-0}))
local param2=$((10#${BASH_REMATCH[2]:-0}))
((_ble_term_mouse_button=128,
_ble_term_mouse_x=param1-1,
_ble_term_mouse_y=param2-1))
Expand All @@ -950,7 +950,7 @@ function ble-decode-char/csi/.decode {
key=${_ble_decode_csimap_alpha[char]}
if [[ $key ]]; then
if rex='^(1?|>?1;([0-9]+))$' && [[ $_ble_decode_csi_args =~ $rex ]]; then
local param2=$((10#${BASH_REMATCH[2]}))
local param2=$((10#${BASH_REMATCH[2]:-0}))
ble-decode-char/csi/.modify-key "$param2"
csistat=$key
return 0
Expand Down
4 changes: 2 additions & 2 deletions src/util.sh
Expand Up @@ -4828,7 +4828,7 @@ if ((_ble_bash>=40000)); then
local command=$1 i removed=
for i in "${!_ble_util_idle_task[@]}"; do
[[ ${_ble_util_idle_task[i]} == *"$_ble_util_idle_SEP$command" ]] &&
unset -v '_ble_util_idle_task[i]' &&
builtin unset -v '_ble_util_idle_task[i]' &&
removed=1
done
[[ $removed ]]
Expand Down Expand Up @@ -5422,7 +5422,7 @@ function ble/term/DA2/initialize-term {
local rex='^[0-9]*(;[0-9]*)*$'; [[ $_ble_term_DA2R =~ $rex ]] || return
local da2r
ble/string#split da2r ';' "$_ble_term_DA2R"
da2r=("${da2r[@]/#/10#}") # 0で始まっていても 10 進数で解釈
da2r=("${da2r[@]/#/10#0}") # 0で始まっていても10進数で解釈 (#D1570 is-array OK)

case $_ble_term_DA2R in
('1;0'?????';0')
Expand Down

0 comments on commit 2ea48d7

Please sign in to comment.