Skip to content

sed: support the \` and \' buffer anchors - #613

Open
jayhemnani9910 wants to merge 1 commit into
uutils:mainfrom
jayhemnani9910:buffer-anchors
Open

jayhemnani9910 wants to merge 1 commit into
uutils:mainfrom
jayhemnani9910:buffer-anchors

Conversation

@jayhemnani9910

Copy link
Copy Markdown

GNU sed's \` and \' match only at the start and end of the pattern space, also with the M flag where ^ and $ match at every line. Here they are passed to the regex engine as is, which reads them as an escaped backtick and quote, so they never match:

$ printf 'ab\ncd\n' | ./target/debug/sed 's/\`./X/g'
ab
cd
$ printf 'ab\ncd\n' | /usr/bin/sed 's/\`./X/g'    # GNU sed 4.9
Xb
Xd

The parser now writes them as \A and \z, which both regex engines know. That also sends patterns like s/\`a/X/ to the regex matcher instead of the literal one, the same way \b already does. Inside brackets, in the replacement, as the delimiter and with --posix they stay literal characters, as before.

Tests: test_buffer_start_and_end_anchors covers s/\`./X/g, the M flag case (N;s/\`/>/Mg;s/\'/</Mg gives >ab\ncd<) and the literal-only case, with GNU sed 4.9's output. It fails without the change. cargo test: 747 passed (746 on main plus the new one), clippy and rustfmt clean. I also checked ERE mode, addresses, the C locale, back-references next to an anchor, ` and ' as delimiters and --posix against GNU sed: all the same.

GNU sed's \` and \' match only at the start and end of the pattern
space, also in M mode. They were passed to the regex engine as is, which
reads them as a literal backtick and quote, so s/\`./X/ never matched.
Spell them as \A and \z, which also sends the pattern to the regex
matcher instead of the literal one.
Copilot AI balanced review requested due to automatic review settings October 20, 2026 05:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.94%. Comparing base (3e86e42) to head (77e6121).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #613   +/-   ##
=======================================
  Coverage   94.93%   94.94%           
=======================================
  Files          14       14           
  Lines        7292     7295    +3     
  Branches      434      434           
=======================================
+ Hits         6923     6926    +3     
  Misses        368      368           
  Partials        1        1           
Flag Coverage Δ
macos_latest 96.46% <100.00%> (+<0.01%) ⬆️
ubuntu_latest 96.40% <100.00%> (+<0.01%) ⬆️
windows_latest 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants