Skip to content

sed: implement \\U \\L \\u \\l \\E case-conversion escapes in s/// - #557

Open
dedsec-terminal wants to merge 21 commits into
uutils:mainfrom
dedsec-terminal:fix-540-case-conversion-escapes
Open

dedsec-terminal wants to merge 21 commits into
uutils:mainfrom
dedsec-terminal:fix-540-case-conversion-escapes

Conversation

@dedsec-terminal

@dedsec-terminal dedsec-terminal commented Sep 15, 2026 •

Copy link
Copy Markdown

Fixes #540.

Implements GNU s/// replacement case-conversion escapes:

  • \U uppercase until \L/\E, \L lowercase until \U/\E
  • \u/\l one-shot next-character conversion
  • \E ends persistent conversion and clears pending one-shot

Details:

  • New ReplacementPart::{Upper,Lower,UpperFirst,LowerFirst,End} in command.rs; compile_replacement parses them before parse_char_escape so \u/\U in replacements are case-conversion directives rather than \uXXXX/\UXXXXXXXX Unicode escapes (matches GNU sed behavior; README updated accordingly). Escaped delimiter still wins (e.g. sU...U\UU).
  • Runtime append_with_case applies persistent + one-shot to literals, &, \1..\9. Empty matches leave one-shot pending (GNU s/(b?)-/\u\1x/g carry), any produced char consumes it. Fresh state per substituted occurrence so g does not propagate.
  • Factored out case selection into take_case(single, persistent) helper.
  • UTF-8 mode is Unicode-aware with invalid-byte passthrough; byte mode is ASCII-only.

Verified against GNU sed 4.9 including the issue table (ABC DEF, ABc def) plus \U&\E, \U\1-\2, empty-group g cases, \u\l/\l\u last-wins, \U\l/\L\u combos.

Tests: cargo test --lib 385 passed, cargo test --test tests 268 passed, cargo clippy --lib clean, cargo fmt --check clean.

Copilot AI lite review requested due to automatic review settings September 15, 2026 19: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 reached their quota limit.

@github-actions

Copy link
Copy Markdown

GNU sed testsuite comparison:

Test results comparison:
  Current:   TOTAL: 65 / PASSED: 15 / FAILED: 42 / SKIPPED: 8
  Reference: TOTAL: 65 / PASSED: 14 / FAILED: 43 / SKIPPED: 8

Changes from main branch:
  TOTAL: +0
  PASSED: +1
  FAILED: -1

Test improvements (1):
  + utf8-ru

@codecov

codecov Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.36000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.73%. Comparing base (09ddeb0) to head (900328d).

Files with missing lines Patch % Lines
src/sed/command.rs 99.25% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #557      +/-   ##
==========================================
+ Coverage   95.45%   95.73%   +0.28%     
==========================================
  Files          14       14              
  Lines        7762     8344     +582     
  Branches      469      490      +21     
==========================================
+ Hits         7409     7988     +579     
- Misses        352      355       +3     
  Partials        1        1              
Flag Coverage Δ
macos_latest 97.08% <99.36%> (+0.18%) ⬆️
ubuntu_latest 97.02% <99.36%> (+0.18%) ⬆️
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.

@codspeed

codspeed Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 1.29%

⚡ 2 improved benchmarks
❌ 5 regressed benchmarks
✅ 4 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.55%
❌ access_log_translit 948.5 ms 991.4 ms -4.33%
❌ access_log_no_op 1.5 s 1.6 s -3.19%
❌ number_fix 576.1 ms 594 ms -3.01%
❌ access_log_append 1 s 1.1 s -2.94%
⚡ genome_subst 365.7 ms 344.3 ms +6.22%
⚡ access_log_subst 2.1 s 2 s +3.28%

Tip

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


Comparing dedsec-terminal:fix-540-case-conversion-escapes (900328d) with main (09ddeb0)

Open in CodSpeed

Copilot AI review requested due to automatic review settings September 16, 2026 17:26

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.

Copilot AI review requested due to automatic review settings September 16, 2026 20:19

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.

@dedsec-terminal

Copy link
Copy Markdown
Author

Hi @dspinellis — friendly review request on this s/// case-conversion implementation (fixes #540; GNU suite +1, utf8-ru). Just pushed a perf follow-up (fast paths when no conversion directives; 265 tests green, fmt+clippy clean) to address the Codspeed delta. Let me know if you need anything else. Thanks!

@github-actions

Copy link
Copy Markdown

GNU sed testsuite comparison:

Test results comparison:
  Current:   TOTAL: 65 / PASSED: 15 / FAILED: 42 / SKIPPED: 8
  Reference: TOTAL: 65 / PASSED: 14 / FAILED: 43 / SKIPPED: 8

Changes from main branch:
  TOTAL: +0
  PASSED: +1
  FAILED: -1

Test improvements (1):
  + utf8-ru

Copilot AI review requested due to automatic review settings September 17, 2026 18:10

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.

@dedsec-terminal

Copy link
Copy Markdown
Author

Follow-up pushed (23b7709): patch coverage for the fast paths - unit tests for unmatched-group/single-literal fast paths, flag-sync contract panics, LowerFirst invalid-byte handling, compiler case-directive parsing + flag, and end-to-end substitution tests; plus removal of two dead None arms preempted by the all-None early return. Full suite green (lib + integration), fmt/clippy clean. Remaining reds are not from this change: Android jobs fail in sdkmanager setup, and CodSpeed shows -3.75% on number_fix only (genome/access_log improved; likely noise, happy to dig if you want).

@github-actions

Copy link
Copy Markdown

GNU sed testsuite comparison:

Test results comparison:
  Current:   TOTAL: 65 / PASSED: 15 / FAILED: 42 / SKIPPED: 8
  Reference: TOTAL: 65 / PASSED: 14 / FAILED: 43 / SKIPPED: 8

Changes from main branch:
  TOTAL: +0
  PASSED: +1
  FAILED: -1

Test improvements (1):
  + utf8-ru

Comment thread .github/workflows/GnuComment.yml Resolved
Comment thread src/sed/compiler.rs Resolved
Comment thread src/sed/compiler.rs Resolved
Comment thread src/sed/command.rs Resolved
Comment thread src/sed/command.rs Resolved
Copilot AI review requested due to automatic review settings September 22, 2026 06:10

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.

@github-actions

Copy link
Copy Markdown

GNU sed testsuite comparison:

Test results comparison:
  Current:   TOTAL: 65 / PASSED: 15 / FAILED: 42 / SKIPPED: 8
  Reference: TOTAL: 65 / PASSED: 14 / FAILED: 43 / SKIPPED: 8

Changes from main branch:
  TOTAL: +0
  PASSED: +1
  FAILED: -1

Test improvements (1):
  + utf8-ru

Copilot AI review requested due to automatic review settings September 22, 2026 08:03

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.

@github-actions

Copy link
Copy Markdown

GNU sed testsuite comparison:

Test results comparison:
  Current:   TOTAL: 65 / PASSED: 15 / FAILED: 42 / SKIPPED: 8
  Reference: TOTAL: 65 / PASSED: 14 / FAILED: 43 / SKIPPED: 8

Changes from main branch:
  TOTAL: +0
  PASSED: +1
  FAILED: -1

Test improvements (1):
  + utf8-ru

Copilot AI review requested due to automatic review settings September 22, 2026 09:26

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.

Comment thread src/sed/command.rs Resolved
Copilot AI lite review requested due to automatic review settings November 19, 2026 06:30

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.

🟢 Approval recommended

No active review issues remain, and the change is supported by extensive unit and integration coverage across conversion modes, encoding behavior, POSIX handling, substitutions, and delimiters.

No open issues 🎉

Review effort: Lite

Copilot AI lite review requested due to automatic review settings November 19, 2026 07:06
@dedsec-terminal

dedsec-terminal commented Nov 19, 2026 •

Copy link
Copy Markdown
Author

Thanks for the review, @sylvestre. I simplified the replacement parser and fast paths, cleaned up the tests, and moved the case conversion docs to the GNU extensions section.

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.

🟡 Changes recommended

A critical active finding remains because the new escape classification causes existing replacement expectations to fail, leaving the test suite inconsistent with the intended behavior.

1 open issue

Review effort: Lite

Comment thread src/sed/compiler.rs Resolved
@dedsec-terminal
dedsec-terminal requested review from sylvestre and a lite review from Copilot November 19, 2026 07:16
@github-actions

Copy link
Copy Markdown

GNU sed testsuite comparison:

Test results comparison:
  Current:   TOTAL: 65 / PASSED: 25 / FAILED: 32 / SKIPPED: 8
  Reference: TOTAL: 65 / PASSED: 23 / FAILED: 34 / SKIPPED: 8

Changes from main branch:
  TOTAL: +0
  PASSED: +2
  FAILED: -2

Test improvements (2):
  + subst-replacement
  + utf8-ru

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.

🟢 Approval recommended

No active review issues remain, and the implementation and documentation address the requested GNU sed replacement case-conversion behavior.

No open issues 🎉

1 resolved since last review

Review effort: Lite

@github-actions

Copy link
Copy Markdown

GNU sed testsuite comparison:

Test results comparison:
  Current:   TOTAL: 65 / PASSED: 25 / FAILED: 32 / SKIPPED: 8
  Reference: TOTAL: 65 / PASSED: 23 / FAILED: 34 / SKIPPED: 8

Changes from main branch:
  TOTAL: +0
  PASSED: +2
  FAILED: -2

Test improvements (2):
  + subst-replacement
  + utf8-ru

Copilot AI lite review requested due to automatic review settings November 19, 2026 07:41

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.

🔵 Needs a closer look

The broad replacement parsing/rendering changes across multiple encoding and locale-sensitive paths, together with the ICU addition, warrant human validation on supported targets and locales before approval.

No open issues 🎉

Review effort: Lite

@github-actions

Copy link
Copy Markdown

GNU sed testsuite comparison:

Test results comparison:
  Current:   TOTAL: 65 / PASSED: 25 / FAILED: 32 / SKIPPED: 8
  Reference: TOTAL: 65 / PASSED: 23 / FAILED: 34 / SKIPPED: 8

Changes from main branch:
  TOTAL: +0
  PASSED: +2
  FAILED: -2

Test improvements (2):
  + subst-replacement
  + utf8-ru

Copilot AI lite review requested due to automatic review settings November 22, 2026 05:59

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.

🟡 Changes recommended

The README’s top-level summary inaccurately describes \u scope and omits the newly supported \L, \l, and \E replacement directives, leaving an active documentation issue.

1 open issue

Review effort: Lite

Comment thread README.md Resolved
Copilot AI lite review requested due to automatic review settings November 22, 2026 06:03

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.

🟢 Approval recommended

No active review issues are identified; the noted ICU mapper overhead is a non-blocking performance concern rather than a correctness blocker.

No open issues 🎉

1 resolved since last review

Review effort: Lite

@github-actions

Copy link
Copy Markdown

GNU sed testsuite comparison:

Test results comparison:
  Current:   TOTAL: 65 / PASSED: 25 / FAILED: 32 / SKIPPED: 8
  Reference: TOTAL: 65 / PASSED: 23 / FAILED: 34 / SKIPPED: 8

Changes from main branch:
  TOTAL: +0
  PASSED: +2
  FAILED: -2

Test improvements (2):
  + subst-replacement
  + utf8-ru

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.

s/// replacement: implement the \U \L \u \l \E case-conversion escapes

3 participants