Skip to content

sed: don't count empty matches inside a UTF-8 character - #681

Open
Xnadir wants to merge 2 commits into
uutils:mainfrom
Xnadir:fix/empty-match-utf8-boundaries
Open

Xnadir wants to merge 2 commits into
uutils:mainfrom
Xnadir:fix/empty-match-utf8-boundaries

Conversation

@Xnadir

@Xnadir Xnadir commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Closes #644

In a UTF-8 locale, s/[0-9]*/N/g on é wrote N between the two bytes of the character, because the byte regex engine reports an empty match at every byte offset. substitute now skips an empty match that falls inside a valid multi-byte character, so it is neither counted nor replaced. The C locale is unchanged: each byte is still a character there.

The test covers the issue's three cases (g, 2, 3) and the C-locale behaviour. It fails on main and passes with the fix. On my Windows checkout, 48 other integration tests fail on main as well, before and after this change.

AI disclosure: written with help from Claude Code.

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings November 17, 2026 12:32

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 insufficient remaining quota. Try requesting a review at a lower effort level.

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.

@codspeed

codspeed Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 3.3%

2 warnings

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 4 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

❌ 4 regressed benchmarks
✅ 7 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ no_op_short 2.1 s 2.2 s -4.54%
❌ access_log_append 1 s 1.1 s -3.37%
❌ access_log_no_op 1.5 s 1.6 s -3.19%
❌ genome_subst 365.7 ms 373.5 ms -2.08%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing Xnadir:fix/empty-match-utf8-boundaries (a91b729) with main (1a27699)

Open in CodSpeed

@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.18%. Comparing base (1a27699) to head (a91b729).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #681      +/-   ##
==========================================
+ Coverage   94.14%   94.18%   +0.03%     
==========================================
  Files          14       14              
  Lines        5741     5777      +36     
  Branches      458      462       +4     
==========================================
+ Hits         5405     5441      +36     
  Misses        335      335              
  Partials        1        1              
Flag Coverage Δ
macos_latest 96.14% <100.00%> (+0.02%) ⬆️
ubuntu_latest 96.02% <100.00%> (+0.02%) ⬆️
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.

Copilot AI balanced review requested due to automatic review settings November 17, 2026 14:40

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 insufficient remaining quota. Try requesting a review at a lower effort level.

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.

@sylvestre

Copy link
Copy Markdown
Contributor

sorry but it needs to be rebased

@Xnadir
Xnadir force-pushed the fix/empty-match-utf8-boundaries branch from b461bec to a91b729 Compare November 26, 2026 01:24
Copilot AI balanced review requested due to automatic review settings November 26, 2026 01:24

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 insufficient remaining quota. Try requesting a review at a lower effort level.

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.

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.

sed - s///g writes the replacement between the bytes of a UTF-8 character at empty matches

3 participants