Repository navigation
fix(patsub): literal-backslash pattern markers convert one-for-one - #3974
Merged
Merged
Conversation
caomengxuan666
marked this pull request as ready for review
November 20, 2026 07:40
Member
Author
|
Captain review: verified against the GNU bash 5.3.20 oracle — 16/16 adjacent probes byte-identical after the fix (the 6 previously-wrong forms were all "≥2 consecutive literal backslashes with no other glob characters"). Root cause is a double decode: the pattern decoder already collapses |
This was referenced Nov 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
UNVERIFIED-BY-CAPTAIN
Refs #3963
核实(报告坐实)
报告原文(脚本文件字节形态):
x='a\\b\c'(值 = a、\、b、\、c),printf '%q\n' "${x//\\\\/@}"(模式源码形态为 4 个反斜杠)。a@b\c(%q 形态)——模式匹配值中一对双反斜杠,单个反斜杠保留。a@@b@c——每个反斜杠都被单独替换。与报告(niu 1.5.0 / fb025fc)一致。根因
模式解码器(
decode_parameter_pattern_quotes)把源码中的一对\\消费为一个字面反斜杠标记(PATTERN_LITERAL_BACKSLASH,U+0018),所以源码 4 个反斜杠 = 2 个标记 = 2 个字面反斜杠。但无 glob 字符模式走的字面快路径在normalize_parameter_pattern_backslashes里又把相邻的两个标记折叠成一个\——等于把已经解码完的标记再当成源码转义对二次解码,模式被减半,于是纯字符串搜索按单个反斜杠逐个命中。该函数同时被 glob 路径的pattern_literal_tail_ends尾串计算复用,同病。修法
normalize_parameter_pattern_backslashes(src/executor/parameter_replace.rs)改为严格 1:1:每个标记(U+0018 / U+0014)各转一个真实反斜杠。glob 匹配器本体未动(它本来就把 U+0018 当字面反斜杠原子,带 glob 字符的模式一直正确,见对照表 case9/case12/case13)。本 PR 删除了什么
删除了 normalize 中的 pair 折叠 pass(
PATTERN_LITERAL_BACKSLASH_STR.repeat(2)→\的替换)及其误导性注释;无其他机制被绕过或新增。oracle 对照表(脚本文件探针,两侧同跑;结果为 %q 解码后的值)
${x//\\\\/@},x=a\b\c${x/\\\\/@}${x//\\/@}测试
issue_3963_literal_backslash_markers_convert_one_for_one(normalize 1:1 + pair 匹配 + 三连步进)。cargo test --lib:1281 过 / 1 败,唯一失败unix_file_unary_operators…为 master 同名环境基线(master 1279/1,差额为新增测试)。cargo fmt --check无漂移。