Repository navigation
Conversation
`compile_subst_flags` set `print_flag` unconditionally, so `s/a/b/pp` was accepted and printed the line. GNU sed rejects it with "multiple \`p
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #659 +/- ##
=======================================
Coverage 95.24% 95.25%
=======================================
Files 14 14
Lines 7490 7503 +13
Branches 442 443 +1
=======================================
+ Hits 7134 7147 +13
Misses 355 355
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:
|
| } | ||
|
|
||
| #[test] | ||
| fn test_subst_repeated_p_flag_is_rejected() { |
There was a problem hiding this comment.
could you please make it a rstest with the separated case from the issue too (s/a/b/pgp)?
| .arg("s/a/b/pp") | ||
| .fails() | ||
| .code_is(1) | ||
| .stderr_contains("multiple `p' options to `s' command"); |
There was a problem hiding this comment.
please check the position too, char 8: multiple ...
|
|
||
| #[test] | ||
| fn test_subst_repeated_p_flag_is_rejected() { | ||
| // GNU sed rejects a repeated `p` flag instead of silently accepting it. |
There was a problem hiding this comment.
the test name already says it, this comment can go
The message alone does not pin down where the compiler stopped, so check the full line (`<script argument 1>:1:8`) as the sibling tests do.
|
Both applied in 4731839: the test now asserts the full diagnostic ( |
Problem
s/a/b/ppis accepted and prints the line, where GNU sed rejects a repeatedpflag:Fixes #652.
Root cause
In
compile_subst_flags(src/sed/compiler.rs), the'p'arm assignssubst.print_flag = truewithout checking whether it was already set. The'g'arm and the occurrence-number arm both return a compilation error on a repeat, sopwas the only flag that could be given twice.Fix
Return the same compilation error GNU uses,
multiplep' options tos' command, whenprint_flagis already set. Non-repeated flags,pcombined with other flags (gp,ep,pe,p1), and thep_before_eordering semantics are unchanged.Testing
test_subst_repeated_p_flag_is_rejectedintests/by-util/test_sed.rs: fails on the unpatched tree (test reportsb\nb, exit 0) and passes after the fix (exit 1 plus the GNU message).cargo test --test tests subst: 56 passed.cargo test: 344 passed, 2 pre-existing failures on Windows (test_e_command_no_arg_command_failure,test_e_command_with_arg_command_failure; both also fail on a clean checkout here, an unrelated shell-encoding issue).cargo fmt --checkandcargo clippyare clean.