Repository navigation
grep: stop parsing options at the first operand under POSIXLY_CORRECT - #238
yunusarda-sudo wants to merge 1 commit into
Conversation
| // Narrow down to `-flags` (and `--options`) and strip the leading `-` for easier matching. | ||
| let Some(arg) = arg.strip_prefix(b"-") else { | ||
| // A lone `-` (standard input) is an operand too. | ||
| let Some(arg) = arg.strip_prefix(b"-").filter(|arg| !arg.is_empty()) else { |
There was a problem hiding this comment.
Could've been a simpler && !arg.is_empty() here.
There was a problem hiding this comment.
Switched to && !arg.is_empty().
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #238 +/- ##
==========================================
+ Coverage 97.22% 97.23% +0.01%
==========================================
Files 6 6
Lines 2270 2281 +11
Branches 245 247 +2
==========================================
+ Hits 2207 2218 +11
Misses 63 63
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:
|
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
d162910 to
3037595
Compare
| .pipe_in("Foo\n") | ||
| .fails_with_code(2) | ||
| .stdout_is(*stdout) | ||
| .stderr_contains(format!("{missing}: ")); |
There was a problem hiding this comment.
could you please check the full No such file or directory message? -c: is a bit weak
There was a problem hiding this comment.
Updated to assert the full {missing}: No such file or directory error message.
| /// | ||
| /// With `posixly_correct`, options end at the first operand, as POSIX requires: | ||
| /// a `--` is inserted in front of it and later arguments are left alone. | ||
| fn expand_num_shorthand( |
There was a problem hiding this comment.
the function name doesn't really match anymore, no?
There was a problem hiding this comment.
Renamed to preprocess_args and updated doc comments accordingly.
e34b8bb to
5fdf1c3
Compare
5fdf1c3 to
e24f4e6
Compare
With
POSIXLY_CORRECTset (even to an empty value), GNU grep stops reading options at the first operand, soPOSIXLY_CORRECT=1 grep foo t -isearches a file named-i. We always permuted options to the front and applied-i.expand_num_shorthandalready walks the arguments before clap sees them and knows which ones are operands, so underPOSIXLY_CORRECTit now inserts--in front of the first operand and stops there. A lone-counts as an operand. Trailing-NUMis left alone too. Without the variable nothing changes.The test checks five argument lists with the variable set to
1and to an empty string, comparing against GNU grep 3.11. It fails on main.Closes #183