Skip to content

fix(sed): GNU character escapes, -z joins, unreadable inputs and per-line loop budget - #2600

Merged
chaliy merged 1 commit into
mainfrom
claude/project-thread-1mku65
Oct 7, 2026
Merged

chaliy merged 1 commit into
mainfrom
claude/project-thread-1mku65

Conversation

@chaliy

@chaliy chaliy commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Requested by Михайло · project thread

What changed

  • Character escapes. \xHH, \dNNN, \oNNN and \cX now work in regexes, in replacements and in y. Each one always produces a literal character, so s/z/\x26/ inserts & rather than the match (GNU bug 30794 semantics).
  • Escapes inside brackets. \t and \n work inside bracket expressions, so the common s/^[ \t]*// now strips tabs. Any other backslash inside brackets is still a literal member.
  • -z mode. N, G and H join with NUL, and D and P split on NUL. With the M flag, ^ and $ also match around NUL.
  • Unreadable input files. A file that cannot be read is reported (sed: can't read X: ...) and skipped. The remaining files are still processed, and the exit status is 2.
  • Loop budget. The budget is now counted per input line read. Before, seq 3000 | sed '$!N;P;D' stopped after 1001 lines with a loop-limit warning. The uniq script (:b;$b;N;...;bb) had the same problem on long runs of duplicate lines. Loops that read no input (G;D, :a;s/^/x/;ta) are still stopped.

Why

These come from the sed lane of the pseudo-linus Debian oracle bench. The truncation of $!N;P;D was a real correctness bug on ordinary input sizes.

Before

$ seq 3000 | sed '$!N;P;D' | wc -l
sed: warning: branch/label loop limit (1000) reached on line 1002; output may be truncated
1001
$ echo z | sed 's/z/\x5cA/'      → x5cA
$ printf '\t\tb\n' | sed 's/^[ \t]*//'   → "\t\tb" (tabs kept)
Oracle bench: sed 94.2%

After

$ seq 3000 | sed '$!N;P;D' | wc -l
3000
$ echo z | sed 's/z/\x5cA/'      → \A
$ printf '\t\tb\n' | sed 's/^[ \t]*//'   → b
Oracle bench: sed 99.4%

Risk

Low. The DoS bound is kept: a loop is still capped unless it consumes input, and consuming input is bounded by the input size. L-SED-005 is updated to describe this.

Checklist

  • Unit tests (positive and negative cases), compared against GNU sed 4.9 on the host
  • cargo clippy -D warnings, cargo fmt; sed integration and spec tests pass
  • Limitations and log updated

https://claude.ai/code/session_01VscpEzxtqpCKx5eRMpywNj


Generated by Claude Code

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit 6ff1725 Commit Preview URL

Branch Preview URL
Oct 07 2026, 09:04 PM

@chaliy
chaliy merged commit 29bff01 into main Oct 7, 2026
44 checks passed
@chaliy
chaliy deleted the claude/project-thread-1mku65 branch October 7, 2026 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant