Skip to content

[[ =~ ]] regex operand: carrier bytes (0x0c, 0x14..0x1f) from $'...' or after | never match #3545

Closed

Description

@caomengxuan666

现象

[[ STR =~ REGEX ]] 的 regex 操作数中,载体字节(0x0c、0x14..=0x1f,含 ESC)以 $'...' 字面写出,或以 ${c} 出现在 | 之后时,rubash 不匹配;GNU 5.3.20 匹配。同一字节以 a${c}b 形式出现在操作数开头位置时两边都匹配。非载体控制字节(0x01、0x07、0x7f)两边一致。

发现于 #3489 修复过程(该单的 read 字节域问题已另修,本面与 read 无关)。

复现(脚本文件,master 8b48c16)

for c in $'\x01' $'\x07' $'\x0c' $'\x14' $'\x1b' $'\x1f' $'\x7f'; do
  w="a${c}b"
  [[ $w =~ a${c}b ]] && r1=y || r1=n
  [[ $w =~ $'\x01'|${c} ]] && r2=y || r2=n
  printf '%02x var=%s alt=%s\n' "'$c" $r1 $r2
done
w=$'a\033[0mb'
[[ $w =~ $'\033' ]] && echo lit-y || echo lit-n

GNU 5.3.20(/usr/local/bin/bash):全部 var=y alt=y,lit-y。
rubash:0c/14/1b/1f 为 alt=n,lit-n。

方向

GNU 依据:execute_cmd.c:3975 execute_cond_node() 在 :4068 对 =~ 右操作数做 subst.c:4077 cond_expand_word(..., 2)(quote 形转 regex 时只对引号部分做 sh_backslash_quote 式转义),载体字节本身是数据字节,应原样进入 regcomp。rubash 侧疑为 regex 操作数文本化时把带标载体对还原成裸字节后被载体消费者吃掉(同 #3489 机制族),修面待定界。

Activity

  1. added
    bug
    gnu-baseline
    area:carrier
    on Nov 14, 2026
  2. caomengxuan666 commented on Nov 18, 2026

    @caomengxuan666
    MemberAuthor

    开工:队长车道接手 #3545,工作区 ~/workspace/fix-3545/,分支 fix/3545-regex-operand-carrier-bytes,base db580be(开工时 master 尖)。先定界(conditional.rs / conditional/args.rs regex 操作数文本化面),再钉 fail-first、修绿、开草稿 PR。

  3. caomengxuan666 commented on Nov 18, 2026

    @caomengxuan666
    MemberAuthor

    Fixed by PR #3931 (merged 36cc7d9). 队长复核:头 CI census 77 零新增、自带钉 3/3 绿、goldens 仅基线二名、CLI 全绿;服务器腿齐(fail-first 3/3 红 → 绿腿 3/3,15 个 guard stem 全绿,lib 1280/0/4 双边对齐,-D warnings rc=0)。Closing as fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area:carrierbuggnu-baseline

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions