Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/sed/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,9 @@ pub fn compile_subst_flags(
}

'p' => {
if subst.print_flag {
return compilation_error(lines, line, "multiple `p' options to `s' command");
}
subst.print_flag = true;
// 'p' is applied before 'e' iff 'e' has not been seen yet.
subst.p_before_e = !subst.execute;
Expand Down Expand Up @@ -2734,6 +2737,8 @@ mod tests {

#[rstest]
#[case::multiple_g("gpg", ":3: error: multiple `g' options to `s' command")]
#[case::multiple_p("pgp", ":3: error: multiple `p' options to `s' command")]
#[case::multiple_p_adjacent("pp", ":2: error: multiple `p' options to `s' command")]
#[case::multiple_numbers("2g3", ":3: error: multiple number options to `s' command")]
#[case::w_missing_filename("w ", "missing file path")]
#[case::invalid_flag("z", "invalid substitute flag")]
Expand Down
11 changes: 11 additions & 0 deletions tests/by-util/test_sed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,17 @@ fn test_subst_flags_pe_print_then_execute() {
.stdout_is("echo hi\nhi\n");
}

#[rstest]
#[case::adjacent("s/a/b/pp")]
#[case::separated("s/a/b/pgp")]
fn test_subst_repeated_p_flag_rejected(#[case] script: &str) {
new_ucmd!()
.arg(script)
.fails()
.code_is(1)
.stderr_contains("multiple `p' options to `s' command");
}

#[test]
fn test_subst_e_flag_rejected_with_posix() {
// e flag is rejected at compile time if --posix or --sandbox is provided.
Expand Down
Loading