Repository navigation
Conversation
`s/x/y/2g` (replace the 2nd match and every later one) and `s/x/y/g2` are valid in GNU sed, but were rejected with "multiple 'g' or numeric flags". Track `g` separately from the occurrence number so the two can be combined; repeating either one is still an error.
This was referenced Oct 19, 2026
There was a problem hiding this comment.
🟢 Approval recommended
The parser and execution changes are consistent, regression tests cover the new behavior, and no blocking issues remain.
No open issues 🎉
What changed in this PR
Adds GNU-compatible support for combining a numeric occurrence with sed’s g substitution flag.
Changes:
- Tracks global replacement separately from the occurrence number.
- Replaces the selected match and every later match when combined.
- Tests both flag orders and preserves duplicate-flag rejection.
| File | Description |
|---|---|
| tests/by-util/test_sed.rs | Adds combined-flag and capture replacement tests. |
| src/sed/processor.rs | Applies global replacement from the selected occurrence. |
| src/sed/compiler.rs | Parses numeric and global flags independently; updates tests. |
| src/sed/command.rs | Adds separate global substitution state. |
Review effort: Balanced
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #610 +/- ##
=======================================
Coverage 94.85% 94.86%
=======================================
Files 14 14
Lines 7230 7239 +9
Branches 432 432
=======================================
+ Hits 6858 6867 +9
Misses 371 371
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
s/x/y/2g(replace the 2nd match and every later one) ands/x/y/g2are valid in GNU sed but were rejected with "multiple 'g' or numeric flags in substitute command", and unit tests asserted that.gis now tracked separately from the occurrence number. Repeating either one is still an error.