Repository navigation
sed: reject an ERE quantifier with nothing to repeat - #616
Merged
Merged
Conversation
In an ERE, *, +, ? and {m,n} at the start of the regex or right after
(, |, ^ or $ now fail with GNU's "Invalid preceding regular expression"
error. ^* and $* used to be accepted, and the other cases gave a raw
regex crate error.
Fixes uutils#290
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #616 +/- ##
==========================================
+ Coverage 94.93% 95.07% +0.13%
==========================================
Files 14 14
Lines 7292 7436 +144
Branches 434 439 +5
==========================================
+ Hits 6923 7070 +147
+ Misses 368 365 -3
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:
|
sylvestre
reviewed
Oct 24, 2026
| ("/^*/p", 4), | ||
| ("/$*/p", 4), | ||
| ("/a^+/p", 5), | ||
| ] { |
Contributor
There was a problem hiding this comment.
please add a s case too, e.g. s/*/x/, it goes through the same parser
Contributor
Author
There was a problem hiding this comment.
Added s//x/, s/a|+b/x/ and s/^/x/g. They all get the same error now.
Contributor
|
Thanks for your PR |
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.
In an ERE a quantifier needs something before it to repeat. GNU sed rejects
*,+,?and{m,n}at the start of the regex or right after(,|,^or$with "Invalid preceding regular expression".On main most of these already failed, but with a raw regex crate error (
invalid regex '*': regex parse error ... repetition operator missing expression), and^*,$*anda^*were accepted and matched. Now the regex parser tracks whether the last token can be repeated and reports GNU's message. Like GNU it reports once the whole regex has been read, so the column matches GNU's char number for addresses (/*/pgives 1:3,/a|*b/pgives 1:6,/^*/pgives 1:4). BRE is unchanged since a leading*is literal there.Escaped characters, bracket expressions, groups and other quantifiers still count as something to repeat, so
a**,a+?,()*,(a|)*,[a]*,a{1}*,\(*and\**work as before. I checked every case in the tests against GNU sed 4.9.Added
test_ere_quantifier_without_preceding_atomandtest_ere_quantifier_after_atom. The first fails on main.cargo test,cargo fmt --checkandcargo clippy --all-targets --all-features -D warningspass.Fixes #290